UNPKG

@picovoice/koala-web

Version:

Koala Noise Suppression engine for web browsers (via WebAssembly)

108 lines 5.03 kB
import { KoalaModel, KoalaOptions } from './types'; export declare class KoalaWorker { private readonly _worker; private readonly _version; private readonly _frameLength; private readonly _sampleRate; private readonly _delaySample; private static _wasmSimd; private static _wasmSimdLib; private static _wasmPThread; private static _wasmPThreadLib; private static _sdk; private constructor(); /** * Delay in samples. If the input and output of consecutive calls to `.process()` are viewed as two contiguous * streams of audio data, this delay specifies the time shift between the input and output stream. */ get delaySample(): number; /** * Get Koala engine version. */ get version(): string; /** * Get Koala frame length. */ get frameLength(): number; /** * Get sample rate. */ get sampleRate(): number; /** * Get Koala 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 an instance of the Picovoice Koala Noise Suppression 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 processCallback User-defined callback to run after receiving enhanced pcm result. * The output is not directly the enhanced version of the input PCM, but corresponds to samples that were given in * previous calls to `.process()`. The delay in samples between the start time of the input frame and the start * time of the output frame can be attained from `.delaySample`. * @param model Koala model options. * @param model.base64 The model in base64 string to initialize Koala. * @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 `koala` 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.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.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 the Koala engine. */ static create(accessKey: string, processCallback: (enhancedPcm: Int16Array) => void, model: KoalaModel, options?: KoalaOptions): Promise<KoalaWorker>; /** * Processes a frame of audio in a worker. * The 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; /** * Resets Koala into a state as if it had just been newly created. * Call this function in between calls to `process` that do not provide consecutive frames of audio. */ reset(): Promise<void>; /** * Releases resources acquired by WebAssembly module. */ release(): Promise<void>; /** * Terminates the active worker. Stops all requests being handled by worker. */ terminate(): void; } //# sourceMappingURL=koala_worker.d.ts.map