--- title: SpeechRecognitionAlternative slug: Web/API/SpeechRecognitionAlternative tags: - API - Experimental - Interface - Reference - SpeechRecognitionAlternative - Web Speech API - recognition - speech translation_of: Web/API/SpeechRecognitionAlternative ---
{{APIRef("Web Speech API")}}{{SeeCompatTable}}
Web Speech API の SpeechRecognitionAlternative
インターフェイスは、音声認識サービスにより認識されている一つの単語を表します。
このコードは、私たちの Speech color changer の例から抜粋しました。
recognition.onresult = function(event) { // The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object // The SpeechRecognitionResultList object contains SpeechRecognitionResult objects. // It has a getter so it can be accessed like an array // The first [0] returns the SpeechRecognitionResult at position 0. // Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain individual results. // These also have getters so they can be accessed like arrays. // The second [0] returns the SpeechRecognitionAlternative at position 0. // We then return the transcript property of the SpeechRecognitionAlternative object var color = event.results[0][0].transcript; diagnostic.textContent = 'Result received: ' + color + '.'; bg.style.backgroundColor = color; }
仕様書 | 策定状況 | 備考 |
---|---|---|
{{SpecName('Web Speech API', '#speechreco-alternative', 'SpeechRecognitionAlternative')}} | {{Spec2('Web Speech API')}} |
{{Compat("api.SpeechRecognitionAlternative")}}
アプリ内で音声認識を使用するには、manifest ファイルに次の許可設定を指定する必要があります:
"permissions": { "audio-capture" : { "description" : "Audio capture" }, "speech-recognition" : { "description" : "Speech recognition" } }
特権アプリも必要なため、以下も同様に含める必要があります:
"type": "privileged"