SpeechRecognitionAlternative

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

Web Speech APISpeechRecognitionAlternative インターフェイスは、音声認識サービスにより認識されている一つの単語を表します。

プロパティ

SpeechRecognitionAlternative.transcript 読取専用

認識された単語の transcript を含む文字列を返します。

SpeechRecognitionAlternative.confidence 読取専用

音声認識システムの認識の正しさの信頼度を表す評価を数値で返します。

このコードは、私たちの Speech color changer の例から抜粋しました。

js
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;
};

仕様書

Specification
Web Speech API
# speechreco-alternative

ブラウザーの実装状況

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
SpeechRecognitionAlternative
confidence
transcript

Legend

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

Full support
Full support
No support
No support

Firefox OS の許可設定

アプリ内で音声認識を使用するには、manifest ファイルに次の許可設定を指定する必要があります:

json
"permissions": {
  "audio-capture" : {
    "description" : "Audio capture"
  },
  "speech-recognition" : {
    "description" : "Speech recognition"
  }
}

特権アプリも必要なため、以下も同様に含める必要があります:

json
  "type": "privileged"

関連項目