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
Node.js API

API Reference for the Node.js PvSpeaker SDK (npmjs).


PvSpeaker

class PvSpeaker { }

Class for the PvSpeaker. PvSpeaker can be initialized using the class constructor(). Resources should be cleaned when you are done using the release() method.


PvSpeaker.constructor()

PvSpeaker.constructor(
sampleRate: number,
bitsPerSample: number,
options: {
bufferSizeSecs?: number; // default is 20
deviceIndex?: number; // default is -1
} = {}
) { }

constructor method for PvSpeaker.

Parameters

  • sampleRate number : The sample rate of the audio to be played.
  • bitsPerSample number : The number of bits per sample.
  • options : Optional configuration arguments.
    • bufferSizeSecs number : The size in seconds of the internal buffer used to buffer PCM data - i.e. internal circular buffer will be of size sampleRate * bufferSizeSecs.
    • deviceIndex number : The audio device index to use to play audio. A value of (-1) will use the machine's default audio device.

Returns

  • PvSpeaker: An instance of PvSpeaker.

Throws

  • Error: If an error occurs while initializing PvSpeaker.

PvSpeaker.release()

PvSpeaker.release() { }

Releases resources acquired by PvSpeaker.


PvSpeaker.start()

PvSpeaker.start() { }

Starts the audio output device.

Throws

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

PvSpeaker.stop()

PvSpeaker.stop() { }

Stops the audio output device.

Throws

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

PvSpeaker.write()

PvSpeaker.write(pcm: ArrayBuffer): number { }

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 ArrayBuffer : PCM data to be played.

Returns

  • number : Number of samples that were successfully written.

Throws

  • Error: If an error occurs while writing PCM data.

PvSpeaker.flush()

PvSpeaker.flush(pcm: ArrayBuffer = new ArrayBuffer(0)): number { }

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()) has 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 ArrayBuffer : Optional PCM data to be played.

Returns

  • number : Number of samples that were successfully written.

Throws

  • Error: If an error occurs while writing PCM data.

PvSpeaker.writeToFile()

PvSpeaker.writeToFile(outputPath: string) { }

Writes PCM data passed to PvSpeaker to a specified WAV file.

Parameters

  • outputPath string : Path to the output WAV file where the PCM data will be written.

Throws

  • Error: If an error occurs while writing PCM data to file.

PvSpeaker.getSelectedDevice()

PvSpeaker.getSelectedDevice(): string { }

Returns the name of the selected device used to play audio.

Returns

  • string : The name of the selected audio device.

PvSpeaker.isStarted

PvSpeaker.isStarted: boolean

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


PvSpeaker.sampleRate

PvSpeaker.sampleRate: number

The sample rate matching the value passed to the constructor.


PvSpeaker.bitsPerSample

PvSpeaker.bitsPerSample: number

The bits per sample matching the value passed to the constructor.


PvSpeaker.bufferSizeSecs

PvSpeaker.bufferSizeSecs: number

The buffer size in seconds matching the value passed to the constructor.


PvSpeaker.version

PvSpeaker.version: string

Version of the PvSpeaker.


PvSpeaker.getAvailableDevices()

static PvSpeaker.getAvailableDevices(): string[] { }

Gets the list of available audio devices.

Returns

  • string[] : An array of the available device names.

Throws

  • Error: If an error occurs while getting available audio devices.

Was this doc helpful?

Issue with this doc?

Report a GitHub Issue
PvSpeaker Node.js API
  • PvSpeaker
  • constructor()
  • release()
  • start()
  • stop()
  • write()
  • flush()
  • writeToFile()
  • getSelectedDevice()
  • isStarted
  • sampleRate
  • bitsPerSample
  • bufferSizeSecs
  • version
  • PvSpeaker.getAvailableDevices()
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.