Eskillsfy

Home / Blog / Articles

Articles · 23 Nov 2026

Text to Speech: how it works and how to build one

Read text aloud with your device’s voices. This guide explains what happens behind the button and shows the code, so you can build your own.

What it does

Paste text and listen to it read aloud. Choose from the voices on your device (including Indian English and Hindi on most phones), and change the speed and pitch.

When to use it

  • Listening to articles
  • Checking how text sounds
  • Accessibility and language learning

How to use it

  1. Paste the text.
  2. Pick a voice, speed and pitch.
  3. Press Play.

Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/text-to-speech

How it works

Browsers have a built-in speech engine: the Web Speech API’s speechSynthesis. You create a SpeechSynthesisUtterance with the text, pick one of the device’s voices, set rate and pitch, and call speak().

The list of voices loads asynchronously, so the page listens for the voiceschanged event. Voices differ by device: phones often have Indian English and Hindi voices built in.

Build it yourself

Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.

speak.ts (ts)

export function speak(text: string, voiceName?: string, rate = 1) {
  speechSynthesis.cancel(); // stop anything already playing
  const u = new SpeechSynthesisUtterance(text);
  const v = speechSynthesis.getVoices().find((x) => x.name === voiceName);
  if (v) { u.voice = v; u.lang = v.lang; }
  u.rate = rate;
  speechSynthesis.speak(u);
  return new Promise<void>((resolve) => (u.onend = () => resolve()));
}

// Voices arrive later in Chrome:
speechSynthesis.addEventListener("voiceschanged", () => console.log(speechSynthesis.getVoices()));

Make it production-ready

  • Highlight each word as it is spoken with the boundary event.
  • For downloadable audio, use a cloud text-to-speech API on the server.

Questions

Can I download the audio?

Browsers don’t let pages record their own voices, so the audio plays live only.

Try the Text to Speech

Free, runs in your browser, nothing is uploaded.

Open it