(self, num_audio_frames)
return audio, timestamps[0], timestamps[-1]
Grab at least num_audio_frames frames of audio.

    Record at least num_audio_frames of audio and transform it into a
    numpy array. The term "frame" is in the sense used by PortAudio; see the
    note in the class docstring for details.

    Audio returned will be the earliest audio in the queue; it could be from
    before this function was called.

    Args:
      num_audio_frames: minimum number of samples of audio to grab.

    Returns:
      A tuple of (audio, first_timestamp, last_timestamp).
Grab at least num_audio_frames frames of audio.
Grab at least num_audio_frames frames of audio .
def get_audio(self, num_audio_frames):
    """Grab at least num_audio_frames frames of audio.

    Record at least num_audio_frames of audio and transform it into a
    numpy array. The term "frame" is in the sense used by PortAudio; see the
    note in the class docstring for details.

    Audio returned will be the earliest audio in the queue; it could be from
    before this function was called.

    Args:
      num_audio_frames: minimum number of samples of audio to grab.

    Returns:
      A tuple of (audio, first_timestamp, last_timestamp).
    """
    num_audio_chunks = int(
        math.ceil(num_audio_frames * self._downsample_factor /
                  self.frames_per_chunk))
    logging.debug('Capturing %d chunks to get at least %d frames.',
                  num_audio_chunks, num_audio_frames)
    if num_audio_chunks < 1:
      num_audio_chunks = 1
    try:
      timeout = self.timeout_factor * self._chunk_duration_seconds
      chunks, timestamps = list(
          zip(*[
              self._get_chunk(timeout=timeout) for _ in range(num_audio_chunks)
          ]))
    except queue.Empty:
      error_message = 'Audio capture timed out after %.1f seconds.' % timeout
      logging.error(error_message)
      raise AudioTimeoutError(error_message)

    assert len(chunks) == num_audio_chunks
    logging.debug('Got %d chunks. Chunk 0 has shape %s and dtype %s.',
                  len(chunks), chunks[0].shape, chunks[0].dtype)
    if self._raw_audio_queue.qsize() > (0.8 * self.max_queue_chunks):
      logging.warning('%d chunks remain in the queue.',
                      self._raw_audio_queue.qsize())
    else:
      logging.debug('%d chunks remain in the queue.',
                    self._raw_audio_queue.qsize())

    audio = np.concatenate(chunks)
    if self._downsample_factor != 1:
      audio = resample(audio, self._raw_audio_sample_rate_hz,
                       self.audio_sample_rate_hz)

    logging.debug('Audio array has shape %s and dtype %s.', audio.shape,
                  audio.dtype)
    return audio, timestamps[0], timestamps[-1]
def get_audio ( self , num_audio_frames ) : num_audio_chunks = int ( math . ceil ( num_audio_frames * self . _downsample_factor / self . frames_per_chunk ) ) logging . debug ( 'Capturing %d chunks to get at least %d frames.' , num_audio_chunks , num_audio_frames ) if num_audio_chunks < 1 : num_audio_chunks = 1 try : timeout = self . timeout_factor * self . _chunk_duration_seconds chunks , timestamps = list ( zip ( * [ self . _get_chunk ( timeout = timeout ) for _ in range ( num_audio_chunks ) ] ) ) except queue . Empty : error_message = 'Audio capture timed out after %.1f seconds.' % timeout logging . error ( error_message ) raise AudioTimeoutError ( error_message ) assert len ( chunks ) == num_audio_chunks logging . debug ( 'Got %d chunks. Chunk 0 has shape %s and dtype %s.' , len ( chunks ) , chunks [ 0 ] . shape , chunks [ 0 ] . dtype ) if self . _raw_audio_queue . qsize ( ) > ( 0.8 * self . max_queue_chunks ) : logging . warning ( '%d chunks remain in the queue.' , self . _raw_audio_queue . qsize ( ) ) else : logging . debug ( '%d chunks remain in the queue.' , self . _raw_audio_queue . qsize ( ) ) audio = np . concatenate ( chunks ) if self . _downsample_factor != 1 : audio = resample ( audio , self . _raw_audio_sample_rate_hz , self . audio_sample_rate_hz ) logging . debug ( 'Audio array has shape %s and dtype %s.' , audio . shape , audio . dtype ) return audio , timestamps [ 0 ] , timestamps [ - 1 ]