-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
68 lines (44 loc) · 1.77 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
title: "SpeechRecognition: error event"
short-title: error
slug: Web/API/SpeechRecognition/error_event
page-type: web-api-event
browser-compat: api.SpeechRecognition.error_event
---
{{APIRef("Web Speech API")}}
The **`error`** event of the [Web Speech API](/en-US/docs/Web/API/Web_Speech_API) {{domxref("SpeechRecognition")}} object is fired when a speech recognition error occurs.
## Syntax
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
```js
addEventListener("error", (event) => {});
onerror = (event) => {};
```
## Event type
A {{domxref("SpeechRecognitionErrorEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("SpeechRecognitionErrorEvent")}}
## Event properties
_In addition to the properties listed below, properties from the parent interface, {{domxref("Event")}}, are available._
- {{domxref("SpeechRecognitionErrorEvent.error")}} {{ReadOnlyInline}}
- : Returns the type of error raised.
- {{domxref("SpeechRecognitionErrorEvent.message")}} {{ReadOnlyInline}}
- : Returns a message describing the error in more detail.
## Examples
You can use the `error` event in an [`addEventListener`](/en-US/docs/Web/API/EventTarget/addEventListener) method:
```js
const recognition = new webkitSpeechRecognition() || new SpeechRecognition();
recognition.addEventListener("error", (event) => {
console.error(`Speech recognition error detected: ${event.error}`);
});
```
Or use the `onerror` event handler property:
```js
recognition.onerror = (event) => {
console.error(`Speech recognition error detected: ${event.error}`);
};
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Web Speech API](/en-US/docs/Web/API/Web_Speech_API)