Emerging Interfaces

Getting Started With the Web Speech API: Voice Input and Output With No Server, No API Key

Browsers already ship speech recognition and speech synthesis for free. This tutorial covers the SpeechRecognition and SpeechSynthesis interfaces, their real cross-browser gaps, and how to wire voice into an installation without a cloud dependency.

Voice has a reputation in creative-interface work as something that needs a cloud API, a key, and a billing account before you can even test it. The browser-native Web Speech API skips all three for a real (if imperfect) chunk of that functionality: it exposes speech-to-text and text-to-speech as plain JavaScript interfaces, no account required, directly inside any page that can run a script.

Two separate interfaces, two different stories

The spec actually bundles two unrelated capabilities under one name:

  • SpeechSynthesis — text-to-speech. This part is well-supported, works offline in most browsers, and exposes a list of system voices you can enumerate and pick from.
  • SpeechRecognition — speech-to-text. This part is the one to be careful with: it’s a non-standard, prefixed API in most browsers (webkitSpeechRecognition in Chrome), it’s not implemented at all in Firefox as of this writing, and in Chrome specifically, recognized audio is sent to Google’s servers for processing — it’s “free and in the browser,” but it isn’t local or private the way synthesis is.

Speech output: the easy half

const utterance = new SpeechSynthesisUtterance("Hello from the browser.");
utterance.rate = 1.0;
utterance.pitch = 1.0;

// Voices load asynchronously — wait for them before picking one
speechSynthesis.onvoiceschanged = () => {
  const voices = speechSynthesis.getVoices();
  utterance.voice = voices.find(v => v.lang.startsWith("en")) ?? voices[0];
  speechSynthesis.speak(utterance);
};

That’s a complete, working voice-output loop. getVoices() often returns an empty array on the very first call because voice lists load asynchronously — the onvoiceschanged event is there specifically so you’re not stuck polling for them.

Speech input: the part with real caveats

const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognizer = new SpeechRecognition();
recognizer.continuous = true;
recognizer.interimResults = true;

recognizer.onresult = (event) => {
  const transcript = event.results[event.results.length - 1][0].transcript;
  console.log(transcript);
};

recognizer.start();

continuous: true keeps listening past a single phrase instead of stopping after the first result — essential for an installation that should react to ongoing speech rather than one utterance at a time. Always check window.SpeechRecognition || window.webkitSpeechRecognition exists before calling any of this; on Firefox and several mobile browsers, neither will.

Try it yourself

  1. Build the speech-output snippet first and confirm you can hear a voice — this part works almost everywhere and gives you a baseline that something is functioning.
  2. Add the speech-input snippet behind a feature check, and design a visible fallback (a text input, a button) for browsers where SpeechRecognition is undefined.
  3. For an installation context specifically, test recognition with real ambient noise at the actual install volume — accuracy that looks fine at a desk often falls apart in a loud gallery or event space.
  4. If privacy matters for your use case, be explicit in any documentation or signage that recognized audio may be processed by a third-party cloud service, not handled locally.