このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

SpeechGrammar

Deprecated

Avoid using this feature in new projects. Advancements in speech recognition mean that speech grammars are not needed to achieve low error rates. This feature may be a candidate for removal from web standards or browsers.

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

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

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

コンストラクター

SpeechGrammar.SpeechGrammar()

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

プロパティ

SpeechGrammar.src

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

SpeechGrammar.weight 省略可

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 が返される

仕様書

仕様書
Web Speech API
# speechreco-speechgrammar

ブラウザーの実装状況

関連情報