UNPKG

@picovoice/leopard-react-native

Version:

Picovoice Leopard React Native binding

68 lines (67 loc) 3.56 kB
import type { LeopardTranscript, LeopardOptions } from './leopard_types'; declare class Leopard { private readonly _handle; private readonly _sampleRate; private readonly _version; /** * Gets all available devices that Leopard can use for inference. Each entry in the list can be the `device` argument * of the constructor. * * @returns Array of all available devices that Leopard can use for inference. */ static getAvailableDevices(): Promise<any>; /** * Static creator for initializing Leopard 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 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 Optional configuration arguments. * @param options.enableAutomaticPunctuation Set to `true` to enable automatic punctuation insertion. * @param options.enableDiarization Set to `true` 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 the engine. */ static create(accessKey: string, modelPath: string, device?: string, options?: LeopardOptions): Promise<Leopard>; private constructor(); /** * Process a frame of audio with the speech-to-text engine. * @param frame An array of 16-bit pcm samples. The audio needs to have a sample rate equal to `.sampleRate` and be 16-bit * linearly-encoded. This function operates on single-channel audio. If you wish to process data in a different * sample rate or format consider using `.processFile`. * @returns {Promise<LeopardTranscript>} LeopardTranscript object which contains the transcription results of the engine. */ process(frame: number[]): Promise<LeopardTranscript>; /** * Process a frame of audio with the speech-to-text engine. * @param audioPath Absolute path to the audio file. The supported formats are: `3gp (AMR)`, `FLAC`, `MP3`, * `MP4/m4a (AAC)`, `Ogg`, `WAV` and `WebM`. * @returns {Promise<LeopardTranscript>>} LeopardTranscript object which contains the transcription results of the engine. */ processFile(audioPath: string): Promise<LeopardTranscript>; /** * Frees memory that was allocated for Leopard */ delete(): Promise<any>; /** * Get the audio sample rate required by Leopard. * @returns Required sample rate. */ get sampleRate(): number; /** * Gets the version number of the Leopard library. * @returns Version of Leopard */ 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 Leopard;