/// import { DetectionCallback, PorcupineKeyword, PorcupineModel, PorcupineOptions } from './types'; import { BuiltInKeyword } from './built_in_keywords'; type pv_porcupine_process_type = (object: number, pcm: number, keywordIndex: number) => number; type pv_porcupine_delete_type = (object: number) => void; type pv_sample_rate_type = () => number; type pv_porcupine_frame_length_type = () => number; type pv_porcupine_version_type = () => number; type pv_porcupine_list_hardware_devices_type = (hardwareDevices: number, numHardwareDevices: number) => number; type pv_porcupine_free_hardware_devices_type = (hardwareDevices: number, numHardwareDevices: number) => number; type pv_set_sdk_type = (sdk: number) => void; type pv_get_error_stack_type = (messageStack: number, messageStackDepth: number) => number; type pv_free_error_stack_type = (messageStack: number) => void; /** * JavaScript/WebAssembly Binding for the Picovoice Porcupine wake word engine. * * The instances have JavaScript bindings that wrap the calls to the C library and * do some rudimentary type checking and parameter validation. */ type PorcupineModule = EmscriptenModule & { _pv_free: (address: number) => void; _pv_porcupine_delete: pv_porcupine_delete_type; _pv_porcupine_process: pv_porcupine_process_type; _pv_porcupine_frame_length: pv_porcupine_frame_length_type; _pv_porcupine_version: pv_porcupine_version_type; _pv_porcupine_list_hardware_devices: pv_porcupine_list_hardware_devices_type; _pv_porcupine_free_hardware_devices: pv_porcupine_free_hardware_devices_type; _pv_sample_rate: pv_sample_rate_type; _pv_set_sdk: pv_set_sdk_type; _pv_get_error_stack: pv_get_error_stack_type; _pv_free_error_stack: pv_free_error_stack_type; addFunction: typeof addFunction; ccall: typeof ccall; cwrap: typeof cwrap; }; export declare class Porcupine { private _module?; private readonly _frameLength; private readonly _sampleRate; private readonly _version; private readonly _processMutex; private readonly _objectAddress; private readonly _inputBufferAddress; private readonly _keywordIndexAddress; private readonly _keywordLabels; private readonly _messageStackAddressAddressAddress; private readonly _messageStackDepthAddress; private static _wasmSimd; private static _wasmSimdLib; private static _wasmPThread; private static _wasmPThreadLib; private static _sdk; private static _porcupineMutex; private readonly _keywordDetectionCallback; private readonly _processErrorCallback?; private constructor(); /** * Get Porcupine engine version. */ get version(): string; /** * Get frame length. */ get frameLength(): number; /** * Get sample rate. */ get sampleRate(): number; /** * Get keyword labels. */ get keywordLabels(): Map; /** * Set base64 wasm file with SIMD feature. * @param wasmSimd Base64'd wasm file to use to initialize wasm. */ static setWasmSimd(wasmSimd: string): void; /** * Set base64 SIMD wasm file in text format. * @param wasmSimdLib Base64'd wasm 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 Porcupine wake word engine using either * a '.pv' file in public directory or a base64'd string. * * @param accessKey AccessKey generated by Picovoice Console. * @param keywords - Built-in or object containing a base64 * representation of or path to public binary of a Porcupine keyword model and their sensitivities. * Can be provided as an array or a single keyword. * @param keywordDetectionCallback User-defined callback to run after a keyword is detected. * @param model object containing a base64 string * representation of or path to public binary of a Porcupine parameter model used to initialize Porcupine. * @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 `Porcupine` instances. * @param model.forceWrite Flag to overwrite the model in storage even if it exists. * @param model.version Leopard model version. Set to a higher number to update the model file. * @param options Optional configuration arguments, see PorcupineOptions for details. * @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 Porcupine engine. */ static create(accessKey: string, keywords: Array | PorcupineKeyword | BuiltInKeyword, keywordDetectionCallback: DetectionCallback, model: PorcupineModel, options?: PorcupineOptions): Promise; static _init(accessKey: string, keywordPaths: Array, keywordLabels: Array, keywordDetectionCallback: DetectionCallback, sensitivities: Float32Array, modelPath: string, options?: PorcupineOptions): Promise; /** * 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 needs to be * 16-bit linearly-encoded. Furthermore, the engine operates on single-channel audio. * * @param pcm A frame of audio with properties described above. */ process(pcm: Int16Array): Promise; /** * Releases resources acquired by WebAssembly module. */ release(): Promise; onmessage(e: MessageEvent): Promise; private static initWasm; /** * Lists all available devices that Porcupine can use for inference. * Each entry in the list can be the used as the `device` argument for the `.create` method. * * @returns List of all available devices that Porcupine can use for inference. */ static listAvailableDevices(): Promise; private static getMessageStack; protected static wrapAsyncFunction(module: PorcupineModule, functionName: string, numArgs: number): (...args: any[]) => any; } export {}; //# sourceMappingURL=porcupine.d.ts.map