SpeechRecognition: nomatch 事件

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

Web Speech API 的 nomatch 事件會在語音識別服務返回一個沒有顯著識別結果的最終結果時觸發。

這可能涉及到一定程度的識別,但該識別的 confidence 未達到或超過設定的閾值。

語法

在諸如 addEventListener() 之類的方法中使用事件名稱,或設定事件處理程式屬性。

js
addEventListener("nomatch", (event) => { })

onnomatch = (event) => { }

事件型別

一個 SpeechRecognitionEvent。繼承自 Event

Event SpeechRecognitionEvent

事件屬性

除了下面列出的屬性之外,父介面 Event 的屬性也可使用。

SpeechRecognitionEvent.emma 只讀

返回一個 Extensible MultiModal Annotation markup language (EMMA) — XML — 格式的結果表示。

SpeechRecognitionEvent.interpretation 只讀

返回使用者所說內容的語義含義。

SpeechRecognitionEvent.resultIndex 只讀

返回 SpeechRecognitionResultList "陣列" 中已實際發生更改的最低索引值結果。

SpeechRecognitionEvent.results 只讀

返回一個 SpeechRecognitionResultList 物件,代表當前會話的所有語音識別結果。

示例

您可以在 addEventListener 方法中使用 nomatch 事件

js
const recognition = new (SpeechRecognition || webkitSpeechRecognition)();

recognition.addEventListener("nomatch", () => {
  console.error("Speech not recognized");
});

或者使用 onnomatch 事件處理程式屬性

js
recognition.onnomatch = () => {
  console.error("Speech not recognized");
};

規範

規範
Web Speech API
# eventdef-speechrecognition-nomatch
Web Speech API
# dom-speechrecognition-onnomatch

瀏覽器相容性

另見