SpeechRecognition: error event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Theerror event of theWeb Speech APISpeechRecognition object is fired when a speech recognition error occurs.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
js
addEventListener("error", (event) => { })onerror = (event) => { }Event type
ASpeechRecognitionErrorEvent. Inherits fromEvent.
Event properties
In addition to the properties listed below, properties from the parent interface,Event, are available.
SpeechRecognitionErrorEvent.errorRead onlyReturns the type of error raised.
SpeechRecognitionErrorEvent.messageRead onlyReturns a message describing the error in more detail.
Examples
You can use theerror event in anaddEventListener method:
js
const recognition = new (SpeechRecognition || webkitSpeechRecognition)();recognition.addEventListener("error", (event) => { console.error(`Speech recognition error detected: ${event.error}`);});Or use theonerror event handler property:
js
recognition.onerror = (event) => { console.error(`Speech recognition error detected: ${event.error}`);};Specifications
| Specification |
|---|
| Web Speech API> # eventdef-speechrecognition-error> |
| Web Speech API> # dom-speechrecognition-onerror> |