\n```\n\n### 2) Backend: call the TTS API and return audio\nExample in Node.js/Express:\n```js\nimport express from 'express';\nimport fetch from 'node-fetch';\n\nconst app = express();\napp.use(express.json());\n\napp.post('/api/tts', async (req, res) => {\n const { text } = req.body;\n\n const apiResponse = await fetch('https://api.example.com/tts', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${process.env.TTS_API_KEY}`\n },\n body: JSON.stringify({\n text,\n voice: 'en-US'\n })\n });\n\n if (!apiResponse.ok) {\n return res.status(500).send('TTS failed');\n }\n\n res.setHeader('Content-Type', 'audio/mpeg');\n apiResponse.body.pipe(res);\n});\n\napp.listen(3000);\n```\n\n---\n\n## If you want a quicker option: use the browser’s built-in speech API\nFor simple use cases, you may not need a TTS service at all. Browsers support the **Web Speech API**:\n\n```html\n\n\n\n\n```\n\n### Pros\n- No backend needed\n- Fast and free\n- Easy to implement\n\n### Cons\n- Voice quality varies by device/browser\n- Less control than a real TTS API\n\n---\n\n## Things to consider when choosing a TTS API\n- **Voice quality**\n- **Languages/accents supported**\n- **Streaming vs file-based output**\n- **Latency**\n- **Pricing**\n- **Audio format** like MP3 or WAV\n- **SSML support** for pauses, emphasis, pronunciation\n\n---\n\n## Recommended implementation tips\n- **Validate text length** before sending to the API\n- **Cache generated audio** if the same text is requested often\n- **Use streaming** if the API supports it for faster playback\n- **Add rate limiting** to avoid abuse\n- **Handle errors** gracefully\n- **Sanitize user input** if you allow HTML or markup\n\nIf you want, I can show you:\n- a **full working example** in React, Next.js, or plain HTML/JS\n- how to do it with a specific provider like **OpenAI, Google Cloud TTS, AWS Polly, ElevenLabs, or Azure**"}}}

Prompt

How do I make my website read text aloud with a TTS API?

Artificial Intelligence / Speech & Voice AI1 observationLast seen Oct 11, 2026

Latest observation

Oct 11, 2026OpenAI APIWeb search: off

To make a website read text aloud with a TTS (text-to-speech) API, the basic flow is:

  1. User enters or selects text
  2. Your frontend sends that text to your backend
  3. Your backend calls the TTS API
  4. The API returns audio
  5. You play the audio in the browser

Simple architecture

  • Frontend: gets text and sends it to your server
  • Backend: stores your API key securely and requests speech from the TTS provider
  • Browser: receives the audio file/stream and plays it

Why use a backend?

Don’t put TTS API keys directly in the browser if the API key is secret. Anyone can inspect frontend code and steal it. Use a backend as a proxy.


Example with a generic API

1) Frontend: collect text and request audio

<textarea id="text">Hello, world!</textarea>
<button onclick="speakText()">Speak</button>
<audio id="player" controls></audio>

<script>
async function speakText() {
  const text = document.getElementById('text').value;

  const res = await fetch('/api/tts', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ text })
  });

  const audioBlob = await res.blob();
  const audioUrl = URL.createObjectURL(audioBlob);

  const player = document.getElementById('player');
  player.src = audioUrl;
  player.play();
}
</script>

2) Backend: call the TTS API and return audio

Example in Node.js/Express:

import express from 'express';
import fetch from 'node-fetch';

const app = express();
app.use(express.json());

app.post('/api/tts', async (req, res) => {
  const { text } = req.body;

  const apiResponse = await fetch('https://api.example.com/tts', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${process.env.TTS_API_KEY}`
    },
    body: JSON.stringify({
      text,
      voice: 'en-US'
    })
  });

  if (!apiResponse.ok) {
    return res.status(500).send('TTS failed');
  }

  res.setHeader('Content-Type', 'audio/mpeg');
  apiResponse.body.pipe(res);
});

app.listen(3000);

If you want a quicker option: use the browser’s built-in speech API

For simple use cases, you may not need a TTS service at all. Browsers support the Web Speech API:

<textarea id="text">Hello!</textarea>
<button onclick="speak()">Speak</button>

<script>
function speak() {
  const text = document.getElementById('text').value;
  const utterance = new SpeechSynthesisUtterance(text);
  speechSynthesis.speak(utterance);
}
</script>

Pros

  • No backend needed
  • Fast and free
  • Easy to implement

Cons

  • Voice quality varies by device/browser
  • Less control than a real TTS API

Things to consider when choosing a TTS API

  • Voice quality
  • Languages/accents supported
  • Streaming vs file-based output
  • Latency
  • Pricing
  • Audio format like MP3 or WAV
  • SSML support for pauses, emphasis, pronunciation

Recommended implementation tips

  • Validate text length before sending to the API
  • Cache generated audio if the same text is requested often
  • Use streaming if the API supports it for faster playback
  • Add rate limiting to avoid abuse
  • Handle errors gracefully
  • Sanitize user input if you allow HTML or markup

If you want, I can show you:

  • a full working example in React, Next.js, or plain HTML/JS
  • how to do it with a specific provider like OpenAI, Google Cloud TTS, AWS Polly, ElevenLabs, or Azure

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.