blob: d6415441f3e293c51b5b6864fdef0998e02b2170 (
plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
---
title: 'SpeechRecognition: result event'
slug: Web/API/语音识别/result_event
translation_of: Web/API/SpeechRecognition/result_event
---
<div>{{APIRef("Web Speech API")}} {{SeeCompatTable}}</div>
<p>The <code><strong>result</strong></code> event of the <a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a> is fired when the speech recognition service returns a result — a word or phrase has been positively recognized and this has been communicated back to the app</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Bubbles</th>
<td>No</td>
</tr>
<tr>
<th scope="row">Cancelable</th>
<td>No</td>
</tr>
<tr>
<th scope="row">Interface</th>
<td>{{domxref("SpeechRecognitionEvent")}}</td>
</tr>
<tr>
<th scope="row">Event handler property</th>
<td><code><a href="/en-US/docs/Web/API/SpeechRecognition/onresult">onresult</a></code></td>
</tr>
</tbody>
</table>
<h2 id="Examples">Examples</h2>
<p>This code is excerpted from our <a class="external external-icon" href="https://github.com/mdn/web-speech-api/blob/master/speech-color-changer/script.js">Speech color changer</a> example.</p>
<p>You can use the <code>result</code> event in an <code><a href="/en-US/docs/Web/API/EventTarget/addEventListener">addEventListener</a></code> method:</p>
<pre class="brush: js">var recognition = new webkitSpeechRecognition() || new SpeechRecognition();
recognition.addEventListener('result', function(event) {
var color = event.results[0][0].transcript;
diagnostic.textContent = 'Result received: ' + color + '.';
bg.style.backgroundColor = color;
});
</pre>
<p>Or use the <code><a href="/en-US/docs/Web/API/SpeechRecognition/onresult">onresult</a></code> event handler property:</p>
<pre class="brush: js">recognition.onresult = function(event) {
var color = event.results[0][0].transcript;
diagnostic.textContent = 'Result received: ' + color + '.';
bg.style.backgroundColor = color;
}</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Web Speech API', '#speechreco-events', 'speech recognition events')}}</td>
<td>{{Spec2('Web Speech API')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("api.SpeechRecognition.result_event")}}</p>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li>
</ul>
|