SpeechGrammar

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used 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 が返される

仕様書

Specification
Web Speech API
# speechreco-speechgrammar

ブラウザーの実装状況

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
SpeechGrammar
Experimental
SpeechGrammar() constructor
ExperimentalNon-standard
src
Experimental
weight
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
See implementation notes.
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.

関連項目