SpeechGrammar

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

Web Speech APISpeechGrammar インターフェイスは、認識サービスに認識させたい単語のセットまたは単語パターンを表します。

文法は、JSpeech Grammar Format (JSGF) を使用して定義されています。他の形式も将来サポートされる可能性があります。

コンストラクター

SpeechGrammar.SpeechGrammar() (en-US)

SpeechGrammar オブジェクトを生成します。

プロパティ

SpeechGrammar.src (en-US)

SpeechGrammar オブジェクトのインスタンス内からの文法を含む文字列を設定して返します。

SpeechGrammar.weight (en-US) 省略可

SpeechGrammar オブジェクトの重みづけを設定して返します。

js
var 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 ;";
var recognition = new SpeechRecognition();
var speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;

console.log(speechRecognitionList[0].src); // grammar 変数の内容と同じ値が返される
console.log(speechRecognitionList[0].weight); // 4 行目で設定された weight と同じ値の 1 が返される

仕様

Specification
Web Speech API
# speechreco-speechgrammar

ブラウザーの実装状況

BCD tables only load in the browser

関連項目