def detector_test(): reader = stream.StreamReader( waveFile=wavPath, chunkSize=480, simulate=False, ) cutter = stream.ElementFrameCutter( batchSize=1, width=400, shift=160, ) detector = stream.VectorVADetector(batchSize=50, vadFunc=lambda x: True) chain = base.Chain() chain.add(reader) chain.add(cutter) chain.add(detector) chain.start() chain.wait() print(chain.outPIPE.size())
def batcher_test(): reader = stream.StreamReader( waveFile=wavPath, chunkSize=480, simulate=False, ) cutter = stream.ElementFrameCutter( batchSize=1, width=400, shift=160, ) batcher = stream.VectorBatcher(center=50, ) chain = base.Chain() chain.add(reader) chain.add(cutter) chain.add(batcher) chain.start() chain.wait() print(chain.outPIPE.size())
def subsetter_test(): reader = stream.StreamReader( waveFile=wavPath, chunkSize=480, simulate=False, ) cutter = stream.ElementFrameCutter( batchSize=50, width=400, shift=160, ) subsetter = stream.MatrixSubsetter(nChunk=2, ) chain = base.Chain() chain.add(reader) chain.add(cutter) chain.add(subsetter) chain.start() chain.wait() print(chain.outPIPE.size())
def test_chain(): # Define a component class MyComponent(base.Component): def __init__(self,*args,**kwargs): super().__init__(*args,**kwargs) def core_loop(self): while True: if self.inPIPE.is_empty(): break pack = self.get_packet() self.put_packet(pack) component = MyComponent() # Define a joint def copy_packet(items): return items[0], copy.deepcopy(items[0]) joint = base.Joint(copy_packet, outNums=2) # define the input PIPE pipe = base.PIPE() for i in range(5): pipe.put( base.Packet( {"mfcc":np.ones([5,],dtype="float32") },cid=i, idmaker=0) ) pipe.stop() # Define a chain (container) chain = base.Chain() # Add a component chain.add( component, inPIPE=pipe ) # Add a joint. chain will link the joint to the output of component automatically. chain.add( joint ) # Start and Wait chain.start() chain.wait() # Chain has similiar API with component and joint print( chain.outPIPE ) print( chain.outPIPE[0].size() ) print( chain.outPIPE[1].size() )
def stream_recorder_cutter_chain_test(): recorder = stream.StreamRecorder(oKey="stream") cutter = stream.ElementFrameCutter(batchSize=50, width=400, shift=160, oKey="frames") chain = base.Chain() chain.add(node=recorder) chain.add(cutter, iKey="stream") chain.start() time.sleep(2) chain.stop() chain.wait() print("size:", chain.outPIPE.size()) #stream_recorder_cutter_chain_test()