nodejsLeopard Platform — Node.js API

API Reference for the Node.js Leopard SDK (npm)


Leopard

class Leopard { }

Class for the Leopard Speech-to-Text engine.

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


Leopard.constructor()

Leopard.constructor(
accessKey,
modelPath,
libraryPath
)

Leopard constructor.

Parameters

  • accessKey string : AccessKey obtained from Picovoice Console.
  • modelPath string : Path to the file containing model parameters (.pv).
  • libraryPath string : Path to to the Leopard dynamic library (.node).

Returns

  • Leopard: An instance of Leopard platform.

Leopard.release()

Leopard.release()

Releases resources acquired by Leopard.


Leopard.sampleRate

Leopard.sampleRate()

Getter for audio sample rate accepted by Leopard.

Returns

  • number: Audio sample rate accepted by Leopard.

Leopard.version

Leopard.version()

Getter for version.

Returns


Leopard.process()

Leopard.process(pcm)

Processes given audio data with the speech-to-text engine. The incoming audio needs to have a sample rate equal to .sampleRate and be 16-bit linearly-encoded. Leopard operates on single-channel audio.

Parameters

  • pcm Array<number> : Audio data.

Returns

  • [string, boolean]: Transcription of any newly-transcribed speech (if none is available then an empty string is returned) and a flag indicating if an endpoint has been detected.

Leopard.processFile()

Leopard.processFile(audioPath)

Processes an audio file with the speech-to-text engine.

Parameters

  • audioPath string : Absolute path to the audio file. The file needs to have a sample rate equal to or greater than Leopard.sampleRate. The supported formats are: FLAC, MP3, Ogg, Opus, Vorbis, WAV, and WebM.

Returns

  • string: Inferred transcription.

Errors

Exceptions thrown if an error occurs within Leopard Speech-to-Text engine.

Exceptions:

class PvStatusOutOfMemoryError extends Error {}
class PvStatusIoError extends Error {}
class PvStatusInvalidArgumentError extends Error {}
class PvStatusStopIterationError extends Error {}
class PvStatusKeyError extends Error {}
class PvStatusInvalidStateError extends Error {}
class PvStatusRuntimeError extends Error {}
class PvStatusActivationError extends Error {}
class PvStatusActivationLimitReached extends Error {}
class PvStatusActivationThrottled extends Error {}
class PvStatusActivationRefused extends Error {}

Issue with this doc? Please let us know.