wasmCobra - Web API

API Reference for the Cobra Web SDK (npm).


Cobra

class Cobra implements CobraEngine

Class for the Cobra VAD engine.


Cobra.create()

static async function create(accessKey: string): Promise<Cobra>

Creates an instance of the Cobra voice activity detection (VAD) engine.

Parameters

Returns

  • Cobra : An instance of the Cobra engine.

Cobra.process()

async function process(pcm: Int16Array): Promise<number>

Processes a frame of audio. The required sample rate can be retrieved from 'sampleRate' and the length of frame (number of audio samples per frame) can be retrieved from 'frameLength'. The audio must be single-channel and 16-bit linearly-encoded.

Parameters

  • pcm Int16Array : A frame of audio samples.

Returns

  • number : Probability of voice activity. It is a floating-point number within [0, 1].

Cobra.release()

async function release(): Promise<void>

Releases resources acquired by the Cobra Web SDK.


Cobra.frameLength

get framelength(): number

Number of audio samples per frame.


Cobra.sampleRate

get sampleRate(): number

Audio sample rate accepted by Cobra.


Cobra.version

get version(): string

Cobra version string.


CobraWorkerFactory

class CobraWorkerFactory

Factory class that creates web worker instances of the Cobra VAD engine.


CobraWorkerFactory.create()

static async function create(
accessKey: string,
callback: CallableFunction,
start?: boolean
): Promise<Worker>

Creates Cobra web worker instances. The promise resolves when the worker is ready to process voice data.

Parameters

  • accessKey string : AccessKey obtained from Picovoice Console.
  • callback CallableFunction : User-defined callback invoked when a frame of audio is processed. The callback provides a single parameter 'voiceProbability': a floating-point number within [0, 1].
  • start boolean : Indicates if worker should begin accepting audio as soon as it's initialized.

Returns

  • Worker : A Cobra web worker.

Issue with this doc? Please let us know.