Prompt

How do I generate speech from text in a backend job?

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

Latest observation

Oct 11, 2026OpenAI APIWeb search: off

To generate speech from text in a backend job, you typically use a text-to-speech (TTS) service or library inside your worker process, then save the resulting audio file and return/store its URL or path.

Common approach

  1. Queue a background job

    • Your app stores the text and metadata in a DB.
    • A job queue/worker picks it up asynchronously.
  2. Call a TTS engine

    • Cloud APIs: Google Cloud TTS, Amazon Polly, Azure TTS, OpenAI TTS, etc.
    • Local/open-source: e.g. Coqui TTS, Piper, Festival, eSpeak.
  3. Write the audio to storage

    • Save as .mp3, .wav, etc.
    • Upload to S3/GCS/local disk/object storage.
  4. Mark the job complete

    • Save audio URL/path and status in your DB.
    • Notify frontend if needed.

Example flow

Pseudocode

Job starts
  -> load text from DB
  -> sanitize/validate text
  -> call TTS API
  -> receive audio bytes
  -> save audio file
  -> update job record with file URL
  -> done

Example in Node.js using a cloud TTS API

import fs from "fs";
import path from "path";

async function generateSpeech(text, outputPath) {
  const response = await fetch("https://api.example-tts.com/speak", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${process.env.TTS_API_KEY}`
    },
    body: JSON.stringify({
      text,
      voice: "alloy",
      format: "mp3"
    })
  });

  if (!response.ok) {
    throw new Error(`TTS failed: ${response.statusText}`);
  }

  const arrayBuffer = await response.arrayBuffer();
  const buffer = Buffer.from(arrayBuffer);
  fs.writeFileSync(outputPath, buffer);
  return outputPath;
}

Example in Python using a TTS SDK

import requests

def generate_speech(text, output_file):
    r = requests.post(
        "https://api.example-tts.com/speak",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"text": text, "voice": "alloy", "format": "mp3"},
        timeout=60,
    )
    r.raise_for_status()

    with open(output_file, "wb") as f:
        f.write(r.content)

    return output_file

Backend job considerations

  • Async processing: TTS can be slow, so don’t do it in the request thread.
  • Chunk long text: Some APIs have text-length limits.
  • Retries: Network/API failures happen.
  • Rate limiting: Respect provider limits.
  • Caching: If the same text is requested often, reuse existing audio.
  • Security: Validate text; avoid exposing API keys.
  • Audio format: MP3 is common for web delivery, WAV for higher quality/editing.

If you want local generation

You can run a model on your server and avoid external APIs, but it requires:

  • More CPU/GPU resources
  • Model setup/maintenance
  • Higher operational complexity

If you want, I can show you a complete backend worker example in Node.js, Python, Go, or Rails using a specific TTS provider.

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.