Text to Speech in the Browser - No Server, No Cost, No Excuses
How I built a multilingual Text to Speech app using only the browser's built-in Web Speech API - no backend, no API key, no cost. Part 1 of the build-it-small series.
Most developers, when they think about Text to Speech, immediately reach for a cloud API. Google Cloud TTS, Amazon Polly, Azure Speech, ElevenLabs. They set up an account, grab a key, wire up a backend, and start paying per character.
But there is another way. Your browser already has a speech engine built in, and it is free, it is fast, and it works offline.
The Web Speech API
The SpeechSynthesis interface has been available in Chrome since 2014, in Edge, Safari, and Firefox for years. It is not a niche API, it is standard, stable, and ships with every major browser.
The simplest possible usage:
const utterance = new SpeechSynthesisUtterance('Hello, world')
window.speechSynthesis.speak(utterance)
That is it. No imports, no API key, no fetch call. Two lines and your browser speaks.
What I Built
For the first project in the build-it-small series, I built a clean multilingual TTS app with React and Tailwind. Features:
- Voice selector showing every voice installed on the user's device
- Speed control (0.5x to 2x)
- Pitch control (0.5 to 2)
- Sample texts in English, Spanish, Portuguese, French, and German
- Speak, Pause, and Stop controls
- Works entirely in the browser, zero backend
The sample buttons auto-select a matching voice for each language, so you can hear the difference between a Spanish voice and a German voice in two clicks.
How Voice Selection Works
The available voices depend on the user's device and OS. On macOS you get Siri-quality voices. On Windows you get the Microsoft voices. On Android and iOS, mobile-optimized voices.
One gotcha: voices load asynchronously. You have to listen for the voiceschanged event:
function loadVoices() {
setVoices(window.speechSynthesis.getVoices())
}
loadVoices()
window.speechSynthesis.addEventListener('voiceschanged', loadVoices)
Without this, getVoices() returns an empty array in Chrome.
Why This Matters
This is the same underlying technology behind Alexa, Siri, and Google Assistant at a basic level. The difference is scale and quality - cloud providers train neural TTS models on thousands of hours of audio to produce natural-sounding speech. The browser uses lighter, on-device models.
For most use cases - reading content aloud, accessibility tools, language learning, quick prototypes - the browser is good enough, and the cost difference is enormous.
The Stack
- React 18 + Vite for the app shell
- Tailwind CSS for styling
- Zero dependencies beyond that
- No backend, no environment variables
Clone it, run npm install && npm run dev, and it works. No setup, no accounts.
Try It
The full source is on GitHub: github.com/paolinellih/build-it-small
Look in the 01-tts-browser folder. Fork it, extend it, use it as a starting point for your own project.
Next in the series: Speech to Text in the Browser - same idea, opposite direction. The browser can also listen.