SpeechRecognition: start() method

Limited availability

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

The start() method of the Web Speech API starts the speech recognition service to listen for incoming audio (from a microphone or an audio track) and returns the results of that recognition.

Syntax

js
start()
start(audioTrack)

Parameters

audioTrack Optional

A MediaStreamTrack instance to perform speech recognition on. If not specified, the service attempts to recognize audio from the user's microphone instead.

Return value

None (undefined).

Exceptions

InvalidStateError DOMException

Thrown if an audioTrack is specified and one or both of the following are true:

  • The track's kind property is not audio.
  • The track's readyState property is not live.

Examples

Recognizing speech from a microphone

In our Speech color changer example, we create a new SpeechRecognition object instance using the SpeechRecognition() constructor. Later on, we create a click event handler on a <button> so that when it's clicked, we start the speech recognition service and await audio input from the user's microphone:

js
const recognition = new SpeechRecognition();

const diagnostic = document.querySelector(".output");
const bg = document.querySelector("html");
const startBtn = document.querySelector("button");

startBtn.onclick = () => {
  recognition.start();
  console.log("Ready to receive a color command.");
};

When a result has been successfully recognized, the result event fires. We extract the color that was spoken from the event object by grabbing the transcript of the first SpeechRecognitionAlternative of the first SpeechRecognitionResult in the returned results list. We then set the background color of the <html> element to that color.

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

Recognizing speech from an audio track

This code (excerpted from our audio track recognition demo) shows how to recognize speech from an audio track. To begin with, we create a new SpeechRecognition instance and set its lang to en-US. We then grab a reference to a <button> element and a <p> element to output results and diagnostic information.

js
const recognition = new SpeechRecognition();
recognition.lang = "en-US";

const startBtn = document.querySelector("button");
const diagnostic = document.querySelector(".output");

Next, we add a click event handler to the <button>. When it is clicked, we create a new <audio> element using the Audio() constructor and load an MP3 file into it. Once the MP3 is ready to play (determined by the canplay event), we capture it as a MediaStream using the captureStream() method, then extract its audio MediaStreamTrack using getAudioTracks().

We then play the audio (required for the recognition to take place), and pass the MediaStreamTrack into the start() method to start the recognition.

js
startBtn.addEventListener("click", () => {
  diagnostic.textContent = "";
  console.log("Loading audio track");
  const audioElement = new Audio("cheese-on-toast.mp3");
  audioElement.addEventListener("canplay", () => {
    const stream = audioElement.captureStream();
    const audioTrack = stream.getAudioTracks()[0];
    audioElement.play();
    recognition.start(audioTrack);
    console.log("Recognition started");
  });
});

To output the recognized audio, we listen for the result event. When that fires, we grab the transcript of the first SpeechRecognitionAlternative of the first SpeechRecognitionResult in the returned results list. We output the transcript itself to the output <p> and log its confidence rating to the console.

js
recognition.addEventListener("result", (event) => {
  const speech = event.results[0][0].transcript;
  diagnostic.textContent = `Speech recognized: ${speech}.`;
  console.log(`Confidence: ${event.results[0][0].confidence}`);
});

Specifications

Specification
Web Speech API
# dom-speechrecognition-start

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
start
Chrome – Full support
Chrome 33 (Release date: 2014-02-20)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox 143 (Release date: 2025-09-16)
disabled
disabled From version 143 users must explicitly set the media.webspeech.recognition.enable preference to true. To change preferences in Firefox, visit about:config.
Opera – Full support
Opera 20 (Release date: 2014-03-04)
footnote Full support
Safari – Full support
Safari 14.1 (Release date: 2021-04-26)
footnote Full support
Chrome Android – Full support
Chrome Android 33 (Release date: 2014-02-26)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 20 (Release date: 2014-03-06)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4.3 (Release date: 2014-06-02)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
audioTrack parameter
Experimental
Chrome – Full support
Chrome 135 (Release date: 2025-04-01)
footnote Full support
Edge – Full support
Edge 135 (Release date: 2025-04-04)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 120 (Release date: 2025-07-02)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

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

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.

See also