Back to Content

SpeechRecognitionResult

files/en-us/web/api/speechrecognitionresult/index.md

latest1.5 KB
Original Source

{{APIRef("Web Speech API")}}

The SpeechRecognitionResult interface of the Web Speech API represents a single recognition match, which may contain multiple {{domxref("SpeechRecognitionAlternative")}} objects.

Instance properties

  • {{domxref("SpeechRecognitionResult.isFinal")}} {{ReadOnlyInline}}
    • : A boolean value that states whether this result is final (true) or not (false) — if so, then this is the final time this result will be returned; if not, then this result is an interim result, and may be updated later on.
  • {{domxref("SpeechRecognitionResult.length")}} {{ReadOnlyInline}}
    • : Returns the length of the "array" — the number of {{domxref("SpeechRecognitionAlternative")}} objects contained in the result (also referred to as "n-best alternatives".)

Instance methods

  • {{domxref("SpeechRecognitionResult.item")}}
    • : A standard getter that allows {{domxref("SpeechRecognitionAlternative")}} objects within the result to be accessed via array syntax.

Examples

This code is excerpted from our Speech color changer example.

js
recognition.onresult = (event) => {
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `Result received: ${color}.`;
  bg.style.backgroundColor = color;
};

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also