SpeechGrammar

已棄用:此特性不再推薦。雖然某些瀏覽器可能仍然支援它,但它可能已經從相關的網路標準中刪除,可能正在刪除過程中,或者可能僅為相容性目的而保留。請避免使用它,如果可能,請更新現有程式碼;請參閱本頁底部的相容性表格以指導您的決策。請注意,此特性可能隨時停止工作。

SpeechGrammar 介面是 Web Speech API 的一部分,它表示一套供識別服務識別的詞語或詞語模式。

語法使用 JSpeech Grammar Format (JSGF) 定義。

注意: 語法概念已從 Web Speech API 中移除。相關的特性仍然保留在規範中,並且仍然被支援的瀏覽器識別以保持向後相容,但它們對語音識別服務沒有影響。

建構函式

SpeechGrammar() 非標準 已棄用

建立一個新的 SpeechGrammar 物件。

例項屬性

SpeechGrammar.src 已棄用

設定並返回 SpeechGrammar 物件例項中包含的語法的字串。

SpeechGrammar.weight 可選 已棄用

設定並返回 SpeechGrammar 物件的權重。

示例

js
const grammar =
  "#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;";
const recognition = new SpeechRecognition();
const speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;

console.log(speechRecognitionList[0].src); // should return the same as the contents of the grammar variable
console.log(speechRecognitionList[0].weight); // should return 1 - the same as the weight set in addFromString.

規範

規範
Web Speech API
# speechreco-speechgrammar

瀏覽器相容性

另見