/** * A polyfill (a "{@link https://ponyfoo.com/articles/polyfills-or-ponyfills | ponyfill}" to be more precise) for the * {@link https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition | SpeechRecognition API} that uses * {@link https://www.speechly.com/ | Speechly} to implement the transcription functionality * * @remarks * The implementation of the {@link https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition | SpeechRecognition spec} * is incomplete, but should enable the majority of use cases * * @packageDocumentation */ /** * Returns a SpeechRecognition implementation that uses a given Speechly app ID * to generate transcriptions using the Speechly API * * @param appId - Speechly app ID * @returns Class that implements the SpeechRecognition interface * @public */ export declare const createSpeechlySpeechRecognition: (appId: string) => SpeechRecognitionClass; /** * Error emitted when the user does not give permission to use the microphone * @public */ export declare const MicrophoneNotAllowedError: SpeechRecognitionErrorEvent_2; /** * Callback that is invoked when transcription ends * @public */ export declare type SpeechEndCallback = () => void; /** * Callback that is invoked when an error occurs * @public */ export declare type SpeechErrorCallback = (speechRecognitionErrorEvent: SpeechRecognitionErrorEvent_2) => void; /** * Subset of the {@link https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition | W3C SpeechRecognition spec} that * can be used for basic transcription * @public */ declare interface SpeechRecognition_2 { /** * Should the microphone listen continuously (true) or should it stop after the first utterance (false)? */ continuous: boolean; /** * Should interim results be emitted? These are parts of an ongoing utterance for which transcription hasn't * completed yet */ interimResults: boolean; /** * Callback that is invoked whenever the transcript updates */ onresult: SpeechRecognitionEventCallback; /** * Callback that is invoked when transcription ends * @param speechRecognitionEvent - Event containing updates to the transcript */ onend: SpeechEndCallback; /** * Callback that is invoked when an error occurs * @param speechRecognitionErrorEvent - Event containing details of the error */ onerror: SpeechErrorCallback; /** * Start transcribing utterances received from the microphone */ start: () => Promise; /** * Stop transcribing utterances received from the microphone, but finish processing the current utterance */ stop: () => Promise; /** * Stop transcribing utterances received from the microphone, and cut off the current utterance */ abort: () => Promise; } export { SpeechRecognition_2 as SpeechRecognition } /** * Transcript for the ongoing utterance, including the level of confidence in that transcript * @public */ declare interface SpeechRecognitionAlternative_2 { /** * Current transcript of the ongoing utterance (the words spoken by the user) */ transcript: string; /** * Level of confidence in the correctness of the transcript (from 0 to 1) */ confidence: number; } export { SpeechRecognitionAlternative_2 as SpeechRecognitionAlternative } /** * Class that implements the SpeechRecognition interface * @public */ export declare interface SpeechRecognitionClass { /** * Does the browser support the APIs needed for this polyfill? */ readonly hasBrowserSupport: boolean; /** * Constructor for a SpeechRecognition implementation */ new (): SpeechRecognition_2; } /** * Data associated with an error emitted from the recognition service * @public */ declare interface SpeechRecognitionErrorEvent_2 { /** * Type of error raised */ error: 'not-allowed' | 'audio-capture'; /** * Message describing the error in more detail */ message: string; } export { SpeechRecognitionErrorEvent_2 as SpeechRecognitionErrorEvent } /** * Data associated with an update to the transcript for the ongoing utterance * @public */ declare interface SpeechRecognitionEvent_2 { /** * List of speech recognition results, containing all transcripts collected in the current session. This represents the * native {@link https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionResultList | SpeechRecognitionResultList}. * Note that the Speechly implementation currently does not maintain a history of results, only returning the single * result for the ongoing utterance */ results: SpeechRecognitionResult_2[]; /** * Index of the earliest speech recognition result that has changed */ resultIndex: number; } export { SpeechRecognitionEvent_2 as SpeechRecognitionEvent } /** * Callback that is invoked whenever the transcript gets updated * @param speechRecognitionEvent - Event containing updates to the transcript * @public */ export declare type SpeechRecognitionEventCallback = (speechRecognitionEvent: SpeechRecognitionEvent_2) => void; /** * Generic error when speech recognition fails due to an unknown cause * @public */ export declare const SpeechRecognitionFailedError: SpeechRecognitionErrorEvent_2; /** * Object containing a transcript for the ongoing utterance and an indicator of whether that transcript is final or not * @public */ declare interface SpeechRecognitionResult_2 { /** * Object containing a transcript for the ongoing utterance (the use of an integer index key is to mimic the * structure used in the native {@link https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionResult | SpeechRecognitionResult spec}), * which contains an "array" of alternative transcripts. In the Speechly implementation, there is never more than one * alternative, so only the first index is specified in the interface */ 0: SpeechRecognitionAlternative_2; /** * Is this transcript "final"? That is, has the transcription algorithm concluded that the utterance has finished and * that the trancript will have no further updates? */ isFinal: boolean; } export { SpeechRecognitionResult_2 as SpeechRecognitionResult } export { }