UNPKG

@picovoice/leopard-web

Version:

Leopard Speech-to-Text engine for web browsers (via WebAssembly)

97 lines 4.62 kB
import { LeopardModel, LeopardOptions, LeopardTranscript } from './types'; export declare class LeopardWorker { private readonly _worker; private readonly _version; private readonly _sampleRate; private static _wasmSimd; private static _wasmSimdLib; private static _wasmPThread; private static _wasmPThreadLib; private static _sdk; private constructor(); /** * Get Leopard engine version. */ get version(): string; /** * Get sample rate. */ get sampleRate(): number; /** * Get Leopard worker instance. */ get worker(): Worker; /** * Set base64 wasm file with SIMD feature. * @param wasmSimd Base64'd wasm SIMD file to use to initialize wasm. */ static setWasmSimd(wasmSimd: string): void; /** * Set base64 wasm file with SIMD feature in text format. * @param wasmSimdLib Base64'd wasm SIMD file in text format. */ static setWasmSimdLib(wasmSimdLib: string): void; /** * Set base64 wasm file with SIMD and pthread feature. * @param wasmPThread Base64'd wasm file to use to initialize wasm. */ static setWasmPThread(wasmPThread: string): void; /** * Set base64 SIMD and thread wasm file in text format. * @param wasmPThreadLib Base64'd wasm file in text format. */ static setWasmPThreadLib(wasmPThreadLib: string): void; static setSdk(sdk: string): void; /** * Creates a worker instance of the Picovoice Leopard 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 model Leopard model options. * @param model.base64 The model in base64 string to initialize Leopard. * @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 `leopard` 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 arguments. * @param options.device String representation of the device (e.g., CPU or GPU) to use. If set to `best`, the most * suitable device is selected automatically. If set to `gpu`, the engine uses the first available GPU device. To select a specific * GPU device, set this argument to `gpu:${GPU_INDEX}`, where `${GPU_INDEX}` is the index of the target GPU. If set to * `cpu`, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this * argument to `cpu:${NUM_THREADS}`, where `${NUM_THREADS}` is the desired number of threads. * @param options.enableAutomaticPunctuation Flag to enable automatic punctuation insertion. * @param options.enableDiarization Flag to enable speaker diarization, which allows Leopard to differentiate speakers * as part of the transcription process. Word metadata will include a `speakerTag` to identify unique speakers. * * @returns An instance of LeopardWorker. */ static create(accessKey: string, model: LeopardModel, options?: LeopardOptions): Promise<LeopardWorker>; /** * Processes audio in a worker. The required sample rate can be retrieved from '.sampleRate'. * The audio needs to be 16-bit linearly-encoded. Furthermore, the engine operates on single-channel audio. * * @param pcm Frame of audio with properties described above. * @param options Optional process arguments. * @param options.transfer Flag to indicate if the buffer should be transferred or not. If set to true, * input buffer array will be transferred to the worker. * @param options.transferCallback Optional callback containing a new Int16Array with contents from 'pcm'. Use this callback * to get the input pcm when using transfer. * * @return A transcript object. */ process(pcm: Int16Array, options?: { transfer?: boolean; transferCallback?: (data: Int16Array) => void; }): Promise<LeopardTranscript>; /** * Releases resources acquired by WebAssembly module. */ release(): Promise<void>; /** * Terminates the active worker. Stops all requests being handled by worker. */ terminate(): void; } //# sourceMappingURL=leopard_worker.d.ts.map