--- title: SpeechRecognition.maxAlternatives slug: Web/API/SpeechRecognition/maxAlternatives tags: - API - Experimental - Property - Reference - SpeechRecognition - Web Speech API - maxAlternatives - recognition - speech translation_of: Web/API/SpeechRecognition/maxAlternatives ---
{{domxref("SpeechRecognition")}} インターフェイスの maxAlternatives
プロパティは {{domxref("SpeechRecognitionResult")}} で提供される {{domxref("SpeechRecognitionAlternative")}} の最大数を設定します。
デフォルト値は 1
です
var myMaxAlternativeNumber = mySpeechRecognition.maxAlternatives; mySpeechRecognition.maxAlternatives = 2;
最大いくつ代替の結果を返すかを表す数
下記のソースコードは Speech color changer を参考しています
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; //recognition.continuous = false; recognition.lang = 'ja-JP'; recognition.interimResults = false; recognition.maxAlternatives = 1; ...
仕様 | 状態 | コメント |
---|---|---|
{{SpecName('Web Speech API', '#dfn-maxalternatives', 'maxAlternatives')}} | {{Spec2('Web Speech API')}} |
{{Compat("api.SpeechRecognition.maxAlternatives")}}
アプリで音声認識を利用する前に、下記の権限を manifest に追加する必要があります。
"permissions": { "audio-capture" : { "description" : "Audio capture" }, "speech-recognition" : { "description" : "Speech recognition" } }
privileged アプリ権限も必要なので、下記も追加が必要です。
"type": "privileged"