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/isfinal | |
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/isfinal')
-rw-r--r-- | files/zh-cn/web/api/speechrecognitionresult/isfinal/index.html | 139 |
1 files changed, 139 insertions, 0 deletions
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> |