SpeechRecognitionAlternative.transcript

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

SpeechRecognitionResult (en-US) インターフェースの transcript 読み取り専用プロパティは、認識したワードの記録を含む文字列を返します。

連続認識において、連続した SpeechRecognitionResult (en-US) の連結がセッションの適切な記録を生成するように、必要に応じて先頭または末尾の空白が含まれます。

構文

var myTranscript = speechRecognitionAlternativeInstance.transcript;

戻り値

このコードは、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
# dom-speechrecognitionalternative-transcript

ブラウザー実装状況

BCD tables only load in the browser

  • [1] Chrome では、SpeechRecognitionare インターフェースにプレフィックスが必要です。そのため、インターフェース名に webkitSpeechRecognition のようなプレフィックスが必要です; また、認識を動作させるには、Web サーバ上から提供する必要があります。
  • [2] about:config の media.webspeech.recognition.enable フラグで有効にできますが、現在の音声認識はデスクトップ版の Firefox では機能しません - 必要な内部権限が整理されればすぐに適切に公開されます。

Firefox OS 許可

アプリで音声認識を使用するには、manifest で次の許可が必要です:

json

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

特権アプリも必要なため、次のものも含める必要があります。

json

  "type": "privileged"

関連項目