UNPKG

@sv-use/core

Version:

A collection of Svelte 5 utilities.

58 lines (57 loc) 2.12 kB
import { type ConfigurableWindow } from '../__internal__/configurable.js'; import type { SpeechRecognition, SpeechRecognitionErrorEvent } from './types.js'; import type { MaybeGetter } from '../__internal__/types.js'; interface CreateSpeechRecognitionOptions extends ConfigurableWindow { /** * Whether continuous results are returned for each recognition, or only a single result. * @default true */ continuous?: boolean; /** * Whether interim results should be returned or not. * * Interim results are results that are not yet final. * @default true */ interimResults?: boolean; /** * The language used for the speech recognition. * * Note that if you pass in a getter and change the language, the service must be stopped first for the change to take effect. * @default 'en-US' */ lang?: MaybeGetter<string>; /** * A number representing the maximum returned alternatives for each result. * @default 1 */ maxAlternatives?: number; /** * A callback for when an error occurs. * @param error The error that occurred. */ onError?: (error: SpeechRecognitionErrorEvent) => void; /** * A callback for when a new result is obtained. * @param transcript The transcript of the result. * @param isFinal Whether the result is final or not. */ onResult?: (transcript: string, isFinal: boolean) => void; } type CreateSpeechRecognitionReturn = { readonly isSupported: boolean; readonly isListening: boolean; readonly isFinal: boolean; readonly recognition: SpeechRecognition | undefined; result: string; error: SpeechRecognitionErrorEvent | null; start: () => void; stop: () => void; }; /** * Reactive controller interface for the recognition service. * @param options Additional options to customize the behavior. * @see https://svelte-librarian.github.io/sv-use/docs/core/create-speech-recognition */ export declare function createSpeechRecognition(options?: CreateSpeechRecognitionOptions): CreateSpeechRecognitionReturn; export {};