Skip to main content

PvSpeaker Binding for Python

PvSpeaker

PvSpeaker is an easy-to-use, cross-platform audio player designed for real-time speech audio processing. It allows developers to send raw PCM frames to an audio device's output stream.

Compatibility

  • Python 3.9+
  • Runs on Linux (x86_64), macOS (x86_64 and arm64), Windows (x86_64, arm64), and Raspberry Pi (3, 4, 5).

Installation

pip3 install pvspeaker

Usage

Initialize and start PvSpeaker:

from pvspeaker import PvSpeaker

speaker = PvSpeaker(
    sample_rate=22050,
    bits_per_sample=16,
    buffer_size_secs=20,
    device_index=0)

speaker.start()

(or)

Use get_available_devices() to get a list of available devices and then initialize the instance based on the index of a device:

from pvspeaker import PvSpeaker

devices = PvSpeaker.get_available_devices()

speaker = PvSpeaker(
    sample_rate=22050,
    bits_per_sample=16,
    buffer_size_secs=20,
    device_index=0)

speaker.start()

Write PCM data to the speaker:

def get_next_audio_frame():
    pass

speaker.write(get_next_audio_frame())

Note: the write() method only writes as much PCM data as the internal circular buffer can currently fit, and returns the length of the PCM data that was successfully written.

When all frames have been written, run flush() to wait for all buffered pcm data (i.e. previously buffered via write()) to be played:

speaker.flush()

Note: calling flush() with PCM data as an argument will both write that PCM data and wait for all buffered PCM data to finish.

def get_remaining_audio_frames():
    pass

speaker.flush(get_remaining_audio_frames())

To stop the audio output device, run stop():

speaker.stop()

Note that in order to stop the audio before it finishes playing, stop must be run on a separate thread from flush.

Once you are done (i.e. no longer need PvSpeaker to write and/or play PCM), free the resources acquired by PvSpeaker by calling delete. Be sure to first call stop if the audio is still playing. Otherwise, if the audio has already finished playing, you do not have to call stop before delete:

speaker.delete()

Demos

pvspeakerdemo provides command-line utilities for playing audio from a file.

Metadata

Release files for pvspeaker 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pvspeaker 1.0.5
File Size Uploaded
pvspeaker-1.0.5.tar.gz 3.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pvspeaker 1.0.5
File Interpreter ABI Platform
pvspeaker-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 7.6 MB

Release files / pvspeaker-1.0.5.tar.gz

Download URL pvspeaker-1.0.5.tar.gz
Size 3.8 MB
Tags Source
SHA-256 checksum
How to use checksums
65b27e074967dd9833baa38dedb0967d756eefbad0a8cb263941cc97fb20b02f
BLAKE2b-256 checksum
How to use checksums
53e09ee158ccb45f089daeabe63f3ba819eab0ea64fa70613746582837b102a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / pvspeaker-1.0.5-py3-none-any.whl

Download URL pvspeaker-1.0.5-py3-none-any.whl
Size 3.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
27d53e119befe3875db8bffad1250cf700389bc5c155334fed112b8f5e4582ee
BLAKE2b-256 checksum
How to use checksums
cfae9984eb73075ec0cf10e191dae2fb49a979c15b0b8501dfbdd736f76c3e14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 release files

1.0.4

1 release file

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page