diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/speechrecognitionresult | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/speechrecognitionresult')
-rw-r--r-- | files/zh-cn/web/api/speechrecognitionresult/index.html | 152 | ||||
-rw-r--r-- | files/zh-cn/web/api/speechrecognitionresult/isfinal/index.html | 139 |
2 files changed, 291 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/speechrecognitionresult/index.html b/files/zh-cn/web/api/speechrecognitionresult/index.html new file mode 100644 index 0000000000..c22e5d7da0 --- /dev/null +++ b/files/zh-cn/web/api/speechrecognitionresult/index.html @@ -0,0 +1,152 @@ +--- +title: SpeechRecognitionResult +slug: Web/API/SpeechRecognitionResult +tags: + - API + - Experimental + - Interface + - NeedsTranslation + - Reference + - SpeechRecognitionResult + - TopicStub + - Web Speech API + - recognition + - speech +translation_of: Web/API/SpeechRecognitionResult +--- +<p>{{APIRef("Web Speech API")}}{{SeeCompatTable}}</p> + +<p>The <strong><code>SpeechRecognitionResult</code></strong> interface of the <a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a> represents a single recognition match, which may contain multiple {{domxref("SpeechRecognitionAlternative")}} objects.</p> + +<h2 id="Properties">Properties</h2> + +<dl> + <dt>{{domxref("SpeechRecognitionResult.isFinal")}} {{readonlyinline}}</dt> + <dd>A {{domxref("Boolean")}} that states whether this result is final (true) or not (false) — if so, then this is the final time this result will be returned; if not, then this result is an interim result, and may be updated later on.</dd> + <dt>{{domxref("SpeechRecognitionResult.length")}} {{readonlyinline}}</dt> + <dd>Returns <cite>the length of the "array" — the </cite>number of {{domxref("SpeechRecognitionAlternative")}} objects contained in the result (also referred to as "n-best alternatives".)</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<dl> + <dt>{{domxref("SpeechRecognitionResult.item")}}</dt> + <dd>A standard getter that allows {{domxref("SpeechRecognitionAlternative")}} objects within the result to be accessed via array syntax.</dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<p>This code is excerpted from our <a href="https://github.com/mdn/web-speech-api/blob/master/speech-color-changer/script.js">Speech color changer</a> example.</p> + +<pre class="brush: js">recognition.onresult = function(event) { + // The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object + // The SpeechRecognitionResultList object contains SpeechRecognitionResult objects. + // It has a getter so it can be accessed like an array + // The first [0] returns the SpeechRecognitionResult at position 0. + // Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain individual results. + // These also have getters so they can be accessed like arrays. + // The second [0] returns the SpeechRecognitionAlternative at position 0. + // We then return the transcript property of the SpeechRecognitionAlternative object + 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-result', 'SpeechRecognitionResult')}}</td> + <td>{{Spec2('Web Speech API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(33)}} <sup>[1]</sup></td> + <td>{{CompatGeckoDesktop(44)}} <sup>[2]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>2.5</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<ul> + <li>[1] Speech recognition interfaces are currently prefixed on Chrome, so you'll need to prefix interface names appropriately, e.g. <code>webkitSpeechRecognition</code>; You'll also need to serve your code through a web server for recognition to work.</li> + <li>[2] Can be enabled via the <code>media.webspeech.recognition.enable</code> flag in <a>about:config</a>, although note that currently speech recognition won't work on Desktop Firefox — it will be properly exposed soon, once the required internal permissions are sorted out.</li> +</ul> + +<h3 id="Firefox_OS_permissions">Firefox OS permissions</h3> + +<p>To use speech recognition in an app, you need to specify the following permissions in your <a href="/en-US/docs/Web/Apps/Build/Manifest">manifest</a>:</p> + +<pre class="brush: json">"permissions": { + "audio-capture" : { + "description" : "Audio capture" + }, + "speech-recognition" : { + "description" : "Speech recognition" + } +}</pre> + +<p>You also need a privileged app, so you need to include this as well:</p> + +<pre class="brush: json"> "type": "privileged"</pre> + +<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> diff --git a/files/zh-cn/web/api/speechrecognitionresult/isfinal/index.html b/files/zh-cn/web/api/speechrecognitionresult/isfinal/index.html new file mode 100644 index 0000000000..1b1a46a1d7 --- /dev/null +++ b/files/zh-cn/web/api/speechrecognitionresult/isfinal/index.html @@ -0,0 +1,139 @@ +--- +title: SpeechRecognitionResult.isFinal +slug: Web/API/SpeechRecognitionResult/isFinal +tags: + - API + - Web Speech API + - isFinal + - 语音 + - 语音识别 +translation_of: Web/API/SpeechRecognitionResult/isFinal +--- +<p>{{APIRef("Web Speech API")}}{{ SeeCompatTable() }}</p> + +<p>{{domxref("SpeechRecognitionResult")}} 接口的<code><strong>isFinal</strong></code>只读属性是一个布尔值, 如果值是<code>true</code>, 则表示这是最后一次返回的结果 (语音识别结束)。如果为<code>false</code>, 表示识别尚未结束, 这只是一个临时的数据, 有可能会在稍后更新。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var myIsFinal = speechRecognitionResultInstance.isFinal;</pre> + +<h3 id="返回值">返回值</h3> + +<p>{{domxref("Boolean")}} </p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">recognition.onresult = function(event) { + // The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object + // SpeechRecognitionResultList 对象包含 SpeechRecognitionResult 对象. + // 它有一个getter,所以它可以像数组一样被访问 + // 第一个[0]返回 SpeechRecognitionResult 的第0个下标. + // Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain individual results. + // 这些也有getter,因此可以像数组一样访问它们。 + // 第二个[0]返回 SpeechRecognitionAlternative 所在的第0个下标。 + // 然后我们返回的记录属性 SpeechRecognitionAlternative 对象 + var color = event.results[0][0].transcript; + diagnostic.textContent = 'Result received: ' + color + '.'; + bg.style.backgroundColor = color; + + console.log(event.results[0].isFinal); +}</pre> + +<h2 id="规格">规格</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规格</th> + <th scope="col">状态</th> + <th scope="col">说明</th> + </tr> + <tr> + <td>{{SpecName('Web Speech API', '#dfn-isFinal', 'isFinal')}}</td> + <td>{{Spec2('Web Speech API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(33)}} <sup>[1]</sup></td> + <td>{{CompatGeckoDesktop(44)}} <sup>[2]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>2.5</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<ul> + <li>[1] 语音识别接口目前是Chrome的前缀, 所以你需要对接口进行添加适当的前缀, 比如, <code>webkitSpeechRecognition</code>; 同时, 你还需要一个来Web服务器来为代码 (API) 服务, 以便识别工作.</li> + <li>[2] 可以通过 <a>about:config</a>(注意, 不同的浏览器会有不同的配置, 比如 chrome 中是 about:flag ) 中 <code>media.webspeech.recognition.enable</code> 标记来启动, 尽管目前的语音识别功能在桌面版 Firefox 浏览器中无法使用 — 一旦解决了所需的内部权限, 它将很快被正确地暴露出来。</li> +</ul> + +<h3 id="Firefox_OS_权限">Firefox OS 权限</h3> + +<p>要在应用程序中使用语音识别,您需要在您的清单中指定以下<a href="/zh-CN/Apps/Build/Manifest">权限</a>:</p> + +<pre class="brush: json">"permissions": { + "audio-capture" : { + "description" : "Audio capture" + }, + "speech-recognition" : { + "description" : "Speech recognition" + } +}</pre> + +<p>你还需要一个有特权的应用程序,所以你也需要把它包含在内:</p> + +<pre class="brush: json"> "type": "privileged"</pre> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li> +</ul> |