Picovoice Wordmark
Start Building
Introduction
Introduction
AndroidC.NETiOSLinuxmacOSNode.jsPythonRaspberry PiWebWindows
AndroidC.NETiOSNode.jsPythonWeb
SummaryPicovoice picoLLMGPTQ
Introduction
AndroidC.NETFlutteriOSJavaLinuxmacOSNode.jsPythonRaspberry PiReactReact NativeRustWebWindows
AndroidC.NETFlutteriOSJavaNode.jsPythonReactReact NativeRustWeb
SummaryPicovoice LeopardAmazon TranscribeAzure Speech-to-TextGoogle ASRGoogle ASR (Enhanced)IBM Watson Speech-to-TextWhisper Speech-to-Text
FAQ
Introduction
AndroidC.NETFlutteriOSJavaLinuxmacOSNode.jsPythonRaspberry PiReactReact NativeRustWebWindows
AndroidC.NETFlutteriOSJavaNode.jsPythonReactReact NativeRustWeb
SummaryPicovoice Cheetah
FAQ
Introduction
AndroidC.NETiOSLinuxmacOSNode.jsPythonRaspberry PiWebWindows
AndroidC.NETiOSNode.jsPythonWeb
SummaryAmazon PollyAzure TTSElevenLabsOpenAI TTSPicovoice Orca
Introduction
AndroidCiOSLinuxmacOSPythonRaspberry PiWebWindows
AndroidCiOSPythonWeb
SummaryPicovoice KoalaMozilla RNNoise
Introduction
AndroidCiOSLinuxmacOSNode.jsPythonRaspberry PiWebWindows
AndroidCNode.jsPythoniOSWeb
SummaryPicovoice EaglepyannoteSpeechBrainWeSpeaker
Introduction
AndroidCiOSLinuxmacOSPythonRaspberry PiWebWindows
AndroidCiOSPythonWeb
SummaryPicovoice FalconAmazon TranscribeAzure Speech-to-TextGoogle Speech-to-Textpyannote
Introduction
AndroidArduinoCChrome.NETEdgeFirefoxFlutteriOSJavaLinuxmacOSMicrocontrollerNode.jsPythonRaspberry PiReactReact NativeRustSafariUnityWebWindows
AndroidC.NETFlutteriOSJavaMicrocontrollerNode.jsPythonReactReact NativeRustUnityWeb
SummaryPorcupineSnowboyPocketSphinx
Wake Word TipsFAQ
Introduction
AndroidCChrome.NETEdgeFirefoxFlutteriOSJavaLinuxmacOSNode.jsPythonRaspberry PiReactReact NativeRustSafariUnityWebWindows
AndroidC.NETFlutteriOSJavaNode.jsPythonReactReact NativeRustUnityWeb
SummaryPicovoice RhinoGoogle DialogflowAmazon LexIBM WatsonMicrosoft LUIS
Expression SyntaxFAQ
Introduction
AndroidC.NETiOSLinuxmacOSNode.jsPythonRaspberry PiRustWebWindows
AndroidC.NETiOSNode.jsPythonRustWeb
SummaryPicovoice CobraWebRTC VAD
FAQ
Introduction
AndroidC.NETFlutteriOSNode.jsPythonReact NativeRustUnityWeb
AndroidC.NETFlutteriOSNode.jsPythonReact NativeRustUnityWeb
Introduction
C.NETNode.jsPython
C.NETNode.jsPython
FAQGlossary

PvSpeaker
Python API

API Reference for the PvSpeaker Python SDK (PyPI).


pvspeaker.PvSpeaker

class PvSpeaker(object)

Class for the PvSpeaker audio player. PvSpeaker is initialized via __init__() method.


pvspeaker.PvSpeaker.__init__()

def __init__(
self,
sample_rate: int,
bits_per_sample: int,
buffer_size_secs: int = 20,
device_index: int = -1) -> PvSpeaker

__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 size sample_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()

def delete(self) -> None

Releases resources acquired by PvSpeaker.


pvspeaker.PvSpeaker.start()

def start(self) -> None

Starts the audio output device.

Throws

  • Error: If an error occurs while starting audio device.

pvspeaker.PvSpeaker.stop()

def stop(self) ->None

Stops the audio output device.

Throws

  • Error: If an error occurs while stopping audio device.

pvspeaker.PvSpeaker.write()

def write(self, pcm: List[int]) -> int

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()

def flush(self, pcm: List[int] = None) -> int

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()

def write_to_file(self, output_path) -> None

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()

PvSpeaker.get_available_devices() -> List[str]

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

self.selected_device: str

The audio device that the given PvSpeaker instance is using.


pvspeaker.PvSpeaker.is_started

self.is_started: bool

Whether the speaker has started and is available to receive PCM frames or not.


pvspeaker.PvSpeaker.sample_rate

self.sample_rate: int

Gets the sample rate matching the value given to __init__().


pvspeaker.PvSpeaker.bits_per_sample

self.bits_per_sample: int

Gets the bits per sample matching the value given to __init__().


pvspeaker.PvSpeaker.buffer_size_secs

self.buffer_size_secs: int

Gets the buffer size in seconds matching the value given to __init__().


pvspeaker.PvSpeaker.version

self.version: str

The version string of the PvSpeaker library.

Was this doc helpful?

Issue with this doc?

Report a GitHub Issue
PvSpeaker Python API
  • pvspeaker.PvSpeaker
  • __init__()
  • delete()
  • start()
  • stop()
  • write()
  • flush()
  • write_to_file()
  • get_available_devices()
  • selected_device
  • is_started
  • sample_rate
  • bits_per_sample
  • buffer_size_secs
  • version
Voice AI
  • Leopard Speech-to-Text
  • Cheetah Streaming Speech-to-Text
  • Orca Text-to-Speech
  • Koala Noise Suppression
  • Eagle Speaker Recognition
  • Falcon Speaker Diarization
  • Porcupine Wake Word
  • Rhino Speech-to-Intent
  • Cobra Voice Activity Detection
Local LLM
  • picoLLM Inference
  • picoLLM Compression
  • picoLLM GYM
Resources
  • Docs
  • Console
  • Blog
  • Use Cases
  • Playground
Sales & Services
  • Consulting
  • Foundation Plan
  • Enterprise Plan
  • Enterprise Support
Company
  • About us
  • Careers
Follow Picovoice
  • LinkedIn
  • GitHub
  • X
  • YouTube
  • AngelList
Subscribe to our newsletter
Terms of Use
Privacy Policy
© 2019-2025 Picovoice Inc.