@picovoice/cheetah-web
Version:
Cheetah Speech-to-Text engine for web browsers (via WebAssembly)
88 lines • 3.93 kB
TypeScript
import { CheetahModel, CheetahOptions, CheetahTranscript } from './types';
export declare class CheetahWorker {
private readonly _worker;
private readonly _version;
private readonly _frameLength;
private readonly _sampleRate;
private static _wasm;
private static _wasmSimd;
private static _sdk;
private constructor();
/**
* Get Cheetah engine version.
*/
get version(): string;
/**
* Get Cheetah frame length.
*/
get frameLength(): number;
/**
* Get sample rate.
*/
get sampleRate(): number;
/**
* Get Cheetah worker instance.
*/
get worker(): Worker;
/**
* Set base64 wasm file.
* @param wasm Base64'd wasm file to use to initialize wasm.
*/
static setWasm(wasm: string): void;
/**
* Set base64 wasm file with SIMD feature.
* @param wasmSimd Base64'd wasm file to use to initialize wasm.
*/
static setWasmSimd(wasmSimd: string): void;
static setSdk(sdk: string): void;
/**
* Creates a worker instance of the Picovoice Cheetah Speech-to-Text engine.
* Behind the scenes, it requires the WebAssembly code to load and initialize before
* it can create an instance.
*
* @param accessKey AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
* @param transcriptCallback User-defined callback to run after receiving transcript result.
* @param model Cheetah model options.
* @param model.base64 The model in base64 string to initialize Cheetah.
* @param model.publicPath The model path relative to the public directory.
* @param model.customWritePath Custom path to save the model in storage.
* Set to a different name to use multiple models across `cheetah` instances.
* @param model.forceWrite Flag to overwrite the model in storage even if it exists.
* @param model.version Version of the model file. Increment to update the model file in storage.
* @param options Optional configuration arguments.
* @param options.endpointDurationSec Duration of endpoint in seconds. A speech endpoint is detected when there is a
* chunk of audio (with a duration specified herein) after an utterance without any speech in it. Set to `0`
* to disable endpoint detection.
* @param options.enableAutomaticPunctuation Flag to enable automatic punctuation insertion.
* @param options.processErrorCallback User-defined callback invoked if any error happens
* while processing the audio stream. Its only input argument is the error message.
*
* @returns An instance of CheetahWorker.
*/
static create(accessKey: string, transcriptCallback: (cheetahTranscript: CheetahTranscript) => void, model: CheetahModel, options?: CheetahOptions): Promise<CheetahWorker>;
/**
* Processes a frame of audio in a worker.
* The transcript result will be supplied with the callback provided when initializing the worker either
* by 'fromBase64' or 'fromPublicDirectory'.
* Can also send a message directly using 'this.worker.postMessage({command: "process", pcm: [...]})'.
*
* @param pcm A frame of audio sample.
*/
process(pcm: Int16Array): void;
/**
* Flushes internal state of the object, sends a message to the worker to transcribe remaining text.
* The transcript result will be supplied with the callback provided when initializing the worker either
* by 'fromBase64' or 'fromPublicDirectory' with 'endpoint=true'.
* Can also send a message directly using 'this.worker.postMessage({command: "flush"})'.
*/
flush(): void;
/**
* Releases resources acquired by WebAssembly module.
*/
release(): Promise<void>;
/**
* Terminates the active worker. Stops all requests being handled by worker.
*/
terminate(): void;
}
//# sourceMappingURL=cheetah_worker.d.ts.map