SpeechRecognitionResult: isFinal 属性

isFinalSpeechRecognitionResult 接口的只读属性,它是一个布尔值,表示此结果是否为最终结果 (true) 或非最终结果 (false) — 如果是最终结果,则此结果将不再返回;如果不是最终结果,则此结果为中间结果,以后可能会更新。

布尔值。

示例

js
recognition.onresult = (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
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `Result received: ${color}.`;
  bg.style.backgroundColor = color;

  console.log(event.results[0].isFinal);
};

规范

规范
Web 语音 API
# dom-speechrecognitionresult-isfinal

浏览器兼容性

BCD 表格仅在启用 JavaScript 的浏览器中加载。

另请参阅