PvSpeaker
Python API
API Reference for the PvSpeaker Python SDK (PyPI).
pvspeaker.PvSpeaker
Class for the PvSpeaker audio player.
PvSpeaker is initialized via __init__()
method.
pvspeaker.PvSpeaker.__init__()
__init__
method for PvSpeaker.
Parameters
sample_rate
int : The sample rate of the audio to be played.bits_per_sample
int : The number of bits per sample.buffer_size_secs
int : The size in seconds of the internal buffer used to buffer pcm data - i.e. internal circular buffer will be of sizesample_rate
*buffer_size_secs
.device_index
int : The index of the audio device to use. A value of (-1) will resort to default device.
Returns
PvSpeaker
: An instance of PvSpeaker.
Throws
Error
: If an error occurs while creating an instance of PvSpeaker.
pvspeaker.PvSpeaker.delete()
Releases resources acquired by PvSpeaker
.
pvspeaker.PvSpeaker.start()
Starts the audio output device.
Throws
Error
: If an error occurs while starting audio device.
pvspeaker.PvSpeaker.stop()
Stops the audio output device.
Throws
Error
: If an error occurs while stopping audio device.
pvspeaker.PvSpeaker.write()
Synchronous call to write PCM data to the internal circular buffer for audio playback. Only writes as much PCM data as the internal circular buffer can currently fit, and returns the number of samples that were successfully written.
Parameters
pcm
List[int] : The PCM data as a list of integers.
Returns
int
: Number of samples that were successfully written.
Throws
Error
: If an error occurs while writing PCM data.
pvspeaker.PvSpeaker.flush()
Synchronous call to write PCM data to the internal circular buffer for audio playback. This call blocks the thread until all PCM data (including PCM data written in previous calls to write()
) have been successfully written and played.
To simply wait for PCM data written in previous calls to write()
to finish playing, call flush()
with no arguments.
Parameters
pcm
List[int] : Optional PCM data as a list of integers.
Returns
int
: Number of samples that were successfully written.
Throws
Error
: If an error occurs while flushing PCM data.
pvspeaker.PvSpeaker.write_to_file()
Writes PCM data passed to PvSpeaker to a specified WAV file.
Parameters
output_path
str : Path to the output WAV file where the PCM data will be written.
pvspeaker.PvSpeaker.get_available_devices()
Gets the list of available audio devices that can be used for playing.
Returns
List[str]
: A list of strings, indicating the names of audio devices.
Throws
Error
: If an error occurs while getting available devices.
pvspeaker.PvSpeaker.selected_device
The audio device that the given PvSpeaker
instance is using.
pvspeaker.PvSpeaker.is_started
Whether the speaker has started and is available to receive PCM frames or not.
pvspeaker.PvSpeaker.sample_rate
Gets the sample rate matching the value given to __init__()
.
pvspeaker.PvSpeaker.bits_per_sample
Gets the bits per sample matching the value given to __init__()
.
pvspeaker.PvSpeaker.buffer_size_secs
Gets the buffer size in seconds matching the value given to __init__()
.
pvspeaker.PvSpeaker.version
The version string of the PvSpeaker
library.