IO

spokestack.io.pyaudio

This module uses pyaudio for input and output processing

class spokestack.io.pyaudio.PyAudioInput(sample_rate, frame_width, exception_on_overflow=True, **kwargs)[source]

This class retrieves audio from an input device

Parameters
  • sample_rate (int) – desired sample rate for input (Hz)

  • frame_width (int) – desired frame width for input (ms)

  • exception_on_overflow (bool) – produce exception for input overflow

close()[source]

Closes the audio stream

Return type

None

property is_active

Stream active property

Returns

‘True’ if stream is active, ‘False’ otherwise

Return type

bool

property is_stopped

Stream stopped property

Returns

‘True’ if stream is stopped, ‘False’ otherwise

Return type

bool

read()[source]

Reads a single frame of audio

Returns

single frame of PCM-16 audio

Return type

np.ndarray

start()[source]

Starts the audio stream

Return type

None

stop()[source]

Stops the audio stream

Return type

None

class spokestack.io.pyaudio.PyAudioOutput(num_channels=1, sample_rate=24000, frames_per_buffer=1024)[source]

Outputs audio to the default system output

Parameters
  • num_channels (int) – number of audio channels

  • sample_rate (int) – sample rate of the audio (Hz)

  • frames_per_buffer (int) – number of audio samples to buffer on the output device

write(frame)[source]

Writes a single frame of audio to output

Parameters

frame (bytes) – a single frame of audio

Return type

None

spokestack.io.sound_device