UNPKG

@picovoice/cheetah-react-native

Version:

Picovoice Cheetah React Native binding

79 lines (78 loc) 4.12 kB
import type { CheetahOptions, CheetahTranscript } from './cheetah_types'; declare class Cheetah { private readonly _handle; private readonly _frameLength; private readonly _sampleRate; private readonly _version; /** * Static creator for initializing Cheetah given the model path. * @param accessKey AccessKey obtained from Picovoice Console (https://console.picovoice.ai/). * @param modelPath Path to the file containing model parameters. * @param options Optional configuration arguments. * @param 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 options.endpointDuration 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 duration to 0 to disable this. Default is 1 second. * @param options.enableAutomaticPunctuation Set to `true` to enable automatic punctuation insertion. * @param options.enableTextNormalization Set to `true` to enable text normalization. Enabling this feature * improves the readability and formatting of Cheetah's transcriptions (e.g. converts number words to digits) * at the cost of some additional latency. * @returns An instance of the engine. */ static create(accessKey: string, modelPath: string, options?: CheetahOptions): Promise<Cheetah>; private constructor(); /** * Gets all available devices that Cheetah can use for inference. Each entry in the list can be the `device` argument * of the constructor. * * @returns Array of all available devices that Cheetah can use for inference. */ static getAvailableDevices(): Promise<any>; /** * Process a frame of audio with the speech-to-text engine. * @param frame An array of 16-bit pcm samples. The number of samples per frame can be attained by calling * `Cheetah.frameLength`. The incoming audio needs to have a sample rate equal to `Cheetah.sampleRate` * and be 16-bit linearly-encoded. Furthermore, Cheetah operates on single-channel audio. * @returns {Promise<CheetahTranscript>} transcript of any newly-transcribed speech (if none is available then an * empty string is returned) and a flag indicating if an endpoint has been detected. */ process(frame: number[]): Promise<CheetahTranscript>; /** * Marks the end of the audio stream, flushes internal state of the object, and returns * any remaining transcribed text. * * @returns {Promise<CheetahTranscript>} Any remaining transcribed text. If none is available then an empty string is returned. */ flush(): Promise<CheetahTranscript>; /** * Frees memory that was allocated for Cheetah */ delete(): Promise<any>; /** * Gets the required number of audio samples per frame. * @returns Required frame length. */ get frameLength(): number; /** * Get the audio sample rate required by Cheetah. * @returns Required sample rate. */ get sampleRate(): number; /** * Gets the version number of the Cheetah library. * @returns Version of Cheetah */ get version(): string; /** * Gets the Error type given a code. * @param code Code name of native Error. * @param message Detailed message of the error. */ private static codeToError; } export default Cheetah;