The SpeechRecognition interface provides a high-level API for performing speech recognition. It supports real-time speech recognition and recognition of audio files, offering flexibility in a variety of use cases.
RecognitionTaskHintHints for the type of task for which speech recognition is used:
'confirmation': For commands like "yes," "no," or "maybe."'dictation': For tasks similar to keyboard dictation.'search': For identifying search terms.'unspecified': For general-purpose speech recognition.SpeechRecognitionResultRepresents the result of speech recognition:
isFinal: Indicates if the transcription is complete and final.text: The transcription as a user-displayable string, with the highest confidence level.supportedLocales: Returns a list of locales supported by the speech recognizer, such as "en-US", "fr-FR", or "zh-CN".isRecognizing: Indicates whether a recognition request is currently active.start(options: object): Promise<boolean>
Starts speech recognition from the device microphone.
locale: Locale string for the desired language (optional).partialResults: Return intermediate results (default: true).addsPunctuation: Automatically add punctuation to results (default: false).requestOnDeviceRecognition: Keep audio data on the device (default: false).taskHint: Specify the recognition task type ('confirmation', 'dictation', 'search', 'unspecified').useDefaultAudioSessionSettings: Use default audio session settings (default: true).onResult: Callback for recognition results (SpeechRecognitionResult).onSoundLevelChanged: Callback for sound level changes (optional).recognizeFile(options: object): Promise<boolean>
Starts recognition for a recorded audio file.
filePath: Path to the audio file.locale: Locale string for the desired language (optional).partialResults: Return intermediate results (default: false).addsPunctuation: Automatically add punctuation to results (default: false).requestOnDeviceRecognition: Keep audio data on the device (default: false).taskHint: Specify the recognition task type ('confirmation', 'dictation', 'search', 'unspecified').onResult: Callback for recognition results (SpeechRecognitionResult).stop(): Promise<void>
Stops an active speech recognition session.
supportedLocales to determine available languages for recognition..wav, .m4a).