Skip to main content

Speaker library for Picovoice.

Project description

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.8+
  • Runs on Linux (x86_64), macOS (x86_64 and arm64), Windows (x86_64), 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 frames of audio:

def get_next_audio_frame():
    pass

speaker.write(get_next_audio_frame())

When all frames have been written, run flush() to wait for all buffered pcm data to be played:

speaker.flush()

To stop playing audio, 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pvspeaker-1.0.1.tar.gz (3.5 MB view details)

Uploaded Source

Built Distribution

pvspeaker-1.0.1-py3-none-any.whl (3.5 MB view details)

Uploaded Python 3

File details

Details for the file pvspeaker-1.0.1.tar.gz.

File metadata

  • Download URL: pvspeaker-1.0.1.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for pvspeaker-1.0.1.tar.gz
Algorithm Hash digest
SHA256 792c93e216f396cb2ed6251024025cdfad8dd03dcd0bb9525c8c036872d840af
MD5 e9f5bfc5f5a1a8e48af35d21d9a769d1
BLAKE2b-256 c97b96e125a1823f5e422088436586c6ee305d5a2f93c293554be21d95f9df65

See more details on using hashes here.

File details

Details for the file pvspeaker-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pvspeaker-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for pvspeaker-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b949d8aaa932f92fa8f35be1cdaf129ae40f534edd9b4c67a3bee44b26645a3
MD5 4779068ab961e94b74ea63dcfee8996f
BLAKE2b-256 c32213a7a0f9329f0b899b9bad1f3c704e5e9197cb7bf15f5e612ac36f197e05

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page