Web Speech API の SpeechRecognitionAlternative
インターフェイスは、音声認識サービスにより認識されている一つの単語を表します。
プロパティ
SpeechRecognitionAlternative.transcript
読取専用- 認識された単語の transcript を含む文字列を返します。
SpeechRecognitionAlternative.confidence
読取専用- 音声認識システムの認識の正しさの信頼度を表す評価を数値で返します。
例
このコードは、私たちの 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;
}
仕様
仕様書 | 策定状況 | 備考 |
---|---|---|
Web Speech API SpeechRecognitionAlternative の定義 |
ドラフト |
ブラウザーの実装状況
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Firefox OS の許可設定
アプリ内で音声認識を使用するには、manifest ファイルに次の許可設定を指定する必要があります:
"permissions": {
"audio-capture" : {
"description" : "Audio capture"
},
"speech-recognition" : {
"description" : "Speech recognition"
}
}
特権アプリも必要なため、以下も同様に含める必要があります:
"type": "privileged"