tools/utilities/pythonlibs/audio/microphone.py
def read(self):
        """ Read the next audio chunk. This method blocks until the audio is available """
        while not self.closed:
            # block until microphone data is ready...         
            result = None            
            self.cv.acquire()            
            try:    
                while len(self.read_buffer) == 0:
                    if self.closed:
                        return None
                    self.cv.wait(0.1)             
                result = self.read_buffer.pop(0)
            except:
                pass
            self.cv.release()
            
            if result is not None:
                # convert int16 data to scaled floats
                data = np.frombuffer(result, dtype=np.int16)
                data = data.astype(float)
                if len(data) < self.sample_size:
                    # pad the last record with zeros so it is valid input also.
                    bigger = np.zeros((self.sample_size))
                    bigger[:len(data)] = data 
                    data = bigger
                elif len(data) > self.sample_size:
                    data = data[:self.sample_size] # just truncate it, might be off by 1 due to rounding errors

                return data * self.audio_scale_factor
        return None
 Read the next audio chunk. This method blocks until the audio is available 
Read the next audio chunk. This method blocks until the audio is available
Read the next audio chunk . This method blocks until the audio is available
def read(self):
        while not self.closed:
            result = None            
            self.cv.acquire()            
            try:    
                while len(self.read_buffer) == 0:
                    if self.closed:
                        return None
                    self.cv.wait(0.1)             
                result = self.read_buffer.pop(0)
            except:
                pass
            self.cv.release()
            if result is not None:
                data = np.frombuffer(result, dtype=np.int16)
                data = data.astype(float)
                if len(data) < self.sample_size:
                    bigger = np.zeros((self.sample_size))
                    bigger[:len(data)] = data 
                    data = bigger
                elif len(data) > self.sample_size:
                    data = data[:self.sample_size] 
                return data * self.audio_scale_factor
        return None
def read ( self ) : while not self . closed : result = None self . cv . acquire ( ) try : while len ( self . read_buffer ) == 0 : if self . closed : return None self . cv . wait ( 0.1 ) result = self . read_buffer . pop ( 0 ) except : pass self . cv . release ( ) if result is not None : data = np . frombuffer ( result , dtype = np . int16 ) data = data . astype ( float ) if len ( data ) < self . sample_size : bigger = np . zeros ( ( self . sample_size ) ) bigger [ : len ( data ) ] = data data = bigger elif len ( data ) > self . sample_size : data = data [ : self . sample_size ] return data * self . audio_scale_factor return None
Read the next audio chunk.
Read the next audio chunk .
""" Read the next audio chunk. This method blocks until the audio is available """ # block until microphone data is ready...          # convert int16 data to scaled floats # pad the last record with zeros so it is valid input also. # just truncate it, might be off by 1 due to rounding errors
self