--- 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> {{Compat("api.SpeechRecognitionResult.isFinal")}} <h2 id="相关链接">相关链接</h2> <ul> <li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li> </ul>