auditok.io.PyAudioSource

class auditok.io.PyAudioSource(sampling_rate=16000, sample_width=2, channels=1, frames_per_buffer=1024, input_device_index=None)[source]

A class for an AudioSource that reads data from built-in microphone using PyAudio (https://people.csail.mit.edu/hubert/pyaudio/).

Parameters:
  • sampling_rate (int, default: 16000) – number of samples per second of audio data.
  • sample_width (int, default: 2) – size in bytes of one audio sample. Possible values: 1, 2 or 4.
  • channels (int, default: 1) – number of channels of audio data.
  • frames_per_buffer (int, default: 1024) – PyAudio number of frames per buffer.
  • input_device_index (None or int, default: None) – PyAudio index of audio device to read audio data from. If None default device is used.
__init__(sampling_rate=16000, sample_width=2, channels=1, frames_per_buffer=1024, input_device_index=None)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([sampling_rate, sample_width, …]) Initialize self.
close() Close audio source.
is_open() Return True if audio source is open, False otherwise.
open() Open audio source.
read(size) Read and return size audio samples at most.

Attributes

ch Number of channels in audio stream (alias for channels).
channels Number of channels in audio stream.
sample_width Number of bytes used to represent one audio sample.
sampling_rate Number of samples per second of audio stream.
sr Number of samples per second of audio stream (alias for sampling_rate).
sw Number of bytes used to represent one audio sample (alias for sample_width).