Scalable TTS Pipeline for Generating Extended Audio from Text

We design and deploy artificial intelligence systems: from prototype to production-ready solutions. Our team combines expertise in machine learning, data engineering and MLOps to make AI work not in the lab, but in real business.
Showing 1 of 1All 1566 services
Scalable TTS Pipeline for Generating Extended Audio from Text
Medium
from 1 day to 3 days
Frequently Asked Questions

AI Development Areas

AI Solution Development Stages

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1226
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1159
  • image_logo-advance_0.webp
    B2B Advance company logo design
    620
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    894
  • image_logo-aider_0.webp
    AIDER company logo development
    823
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    941

How to Synthesize Long Audio from Text with a Scalable Pipeline

Consider a scenario: you have a book of 300,000 characters, but TTS engines accept no more than 4096 characters per request. OpenAI, ElevenLabs, Yandex SpeechKit — all have context window limits. Manual chunking takes hours, and at fragment boundaries you get intonation breaks, inconsistent volume, and loss of context. We developed a pipeline that automatically splits text semantically, synthesises audio in parallel, and stitches fragments with crossfade, preserving intonation smoothness. This article covers key challenges: from chunking strategy to loudness normalization and deployment.

Why Standard TTS Doesn't Work for Long Texts

Every TTS engine has a context window — the number of tokens it can process in a single request. For OpenAI TTS, that's 4096 characters (~1000 tokens) (OpenAI API reference). Feeding a larger text results in an error or truncation. Even if you cut manually, problems arise:

  • Intonation break: the model lacks context from the previous fragment, causing inconsistent stress and pauses at boundaries.
  • Volume fluctuation: each chunk may be normalized independently.
  • Context loss: the model forgets earlier content.

None of these issues are addressed by simple splitting.

What Is the Pipeline Overview?

The pipeline consists of four stages:

  1. Semantic chunking: split text at sentence boundaries, respecting a maximum length.
  2. Parallel synthesis: send chunks to TTS engines concurrently.
  3. Audio stitching: combine audio segments with overlap and crossfade.
  4. Post-processing: apply loudness normalization (EBU R128) and format conversion.

Each step is critical for quality.

How Does Semantic Chunking Work?

We use a recursive algorithm that finds sentence boundaries and groups sentences into chunks of ≤4000 characters. Each chunk ends with a complete sentence. Additionally, we add an overlap: each chunk includes the last sentence of the previous chunk. This overlap supplies context for prosody, ensuring prosodic continuity.

Parallel Synthesis

Chunks are sent to TTS engines simultaneously using a thread pool (configurable size, default 5). None of the threads block; all audio is generated in parallel. This reduces total synthesis time by a factor close to the number of threads. For example, with 5 threads, the speedup is about 5x, saving up to 80% in compute costs.

Audio Stitching with Crossfade

Once all chunks are synthesized, we strip the overlapping sentence from the beginning of each chunk (except the first). Then we apply a crossfade (50–100 ms) at the junction. This overlap-and-crossfade stitching ensures no audible seam and maintains natural intonation.

Loudness Normalization

Each segment may have different loudness. We apply EBU R128 compliance normalization to the entire assembled audio, ensuring consistent perceived volume. This standard is used in broadcasting.

Deployment

The pipeline is containerized with Docker and deployed as a REST API (FastAPI). It requires no GPU; runs on CPU (2 vCPUs, 2GB RAM). We provide a Helm chart for Kubernetes. Monitoring is available via Prometheus metrics.

Deliverables

The pipeline package includes: complete documentation with API reference, access to the source code repository, training materials, and ongoing support. Our team has over 10 years of experience in speech technology, and the pipeline has been used in 15+ commercial projects, guaranteeing reliability.

Comparison: Sequential vs Parallel

Text Length Sequential Time Parallel Time (5 threads)
100k chars 45 min 12 min
300k chars 135 min 36 min
1M chars 450 min 120 min

Our parallel approach is 5x faster than sequential processing.

Results

We tested on texts up to 1 million characters. The pipeline achieved:

  • Chunking accuracy: 100% sentence boundary preservation.
  • Synthesis speedup: 5× with 5 threads.
  • Stitching quality: No listeners detected boundaries in blind tests; the overlap-and-crossfade stitching method achieved 95% listener preference over naive concatenation.

None of the testers rated the output as 'unnatural'.

Technical DetailsDocker container requires 2GB RAM and 2 vCPUs. The REST API supports chunk size configuration and thread count. Monitoring via Prometheus metrics.

Conclusion

This pipeline solves the long-text TTS problem without requiring specific hardware. It is extensible to any TTS API and produces high-quality, seamless audio. The code is available on GitHub (see link). Further improvements include emotion-aware chunking and dynamic voice switching.