@picovoice/porcupine-node
Version:
Picovoice Porcupine Node.js binding
67 lines • 3.35 kB
TypeScript
import { PorcupineInputOptions, PorcupineOptions } from './types';
export default class Porcupine {
private _pvPorcupine;
private _handle;
private readonly _version;
private readonly _sampleRate;
private readonly _frameLength;
/**
* Creates an instance of Porcupine.
* @param {string} accessKey AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).
* @param {Array} keywords Absolute paths to keyword model files (`.ppn`).
* @param {Array} sensitivities Sensitivity values for detecting keywords.
* Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses
* at the cost of increasing the false alarm rate.
* @param options Optional configuration arguments.
* @param {string} options.modelPath Path to the Porcupine model (.pv extension)
* @param {string} options.device String representation of the device (e.g., CPU or GPU) to use for inference.
* 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 {string} options.libraryPath Path to the Porcupine library (.node extension)
*/
constructor(accessKey: string, keywords: string[], sensitivities: number[], options?: PorcupineOptions);
/**
* @returns number of audio samples per frame (i.e. the length of the array provided to the process function)
* @see {@link process}
*/
get frameLength(): number;
/**
* @returns the audio sampling rate accepted by Porcupine
*/
get sampleRate(): number;
/**
* @returns the version of the Porcupine engine
*/
get version(): string;
/**
* Process a frame of pcm audio.
*
* @param {Array} frame of mono, 16-bit, linear-encoded PCM audio.
* The specific array length can be attained by calling `.frameLength`.
* The incoming audio needs to have a sample rate equal to `.sampleRate` and be 16-bit linearly-encoded.
* Porcupine operates on single-channel audio.
* @returns {number} Index of observed keyword at the end of the current frame.
* Indexing is 0-based and matches the ordering of keyword models provided to the constructor.
* If no keyword is detected then it returns -1.
*/
process(frame: Int16Array): number;
/**
* Releases the resources acquired by Porcupine.
*
* Be sure to call this when finished with the instance
* to reclaim the memory that was allocated by the C library.
*/
release(): void;
/**
* Lists all available devices that Porcupine can use for inference. Each entry in the list can be the `device` argument
* of the constructor.
*
* @returns List of all available devices that Porcupine can use for inference.
*/
static listAvailableDevices(options?: PorcupineInputOptions): string[];
private handlePvStatus;
}
//# sourceMappingURL=porcupine.d.ts.map