Search⌘ K
AI Features

Design a Text-to-Speech Generation System

Design a text-to-speech system around a Fish Speech-style model: train it on large text-audio datasets, then serve it through linguistic extraction, voice profiling, speech generation, and moderation.

Text-to-speech (TTS) models are a class of neural networks that convert written text into realistic spoken audio. TTS technology enables dynamic and personalized interactions, allowing machines to convey information in natural, human-like speech, enhancing the user experience in numerous domains.

Speech generation models have evolved rapidly, with advances in natural language processing and audio synthesisAudio synthesis is the artificial production of sound using software, often for music, sound effects, or speech generation. techniques enabling the creation of highly expressive, lifelike voices. Modern TTS models like the NVIDIA Tacotron2 and xTTS aim to produce clear and natural-sounding speech, allowing customization regarding voice tone, emotion, and even accents. These customizable aspects make TTS models valuable in applications that demand high personalization, such as voiceovers for content creation, real-time translation, and assistive technologies. Systems using these models include everything from assistants like Siri to modern LLM-based chatbots like ChatGPT.

Let’s see how to design a robust and versatile text-to-speech system. Our focus will be to design a system capable of handling text inputs and generating high-quality, legible speech from them.

A user’s interaction with a TTS system
A user’s interaction with a TTS system

Requirements

The first step in designing our system is to define its requirements. These requirements ensure that the system can deliver high-quality audio output, manage various user needs, and maintain scalability and reliability in production.

Functional requirements

The core functionalities that our TTS system should support include:

  • Natural language understanding: The system must accurately interpret text input, understanding grammar, punctuation, and semantic nuances to produce coherent and contextually appropriate speech.

  • Speech generation: The system must produce high-quality natural audio with minimal distortion or artifacts.

  • Customization: Users should be able to customize voice options, including parameters for sex, age, accent, and emotional tone.

  • Multiple audio resolutionsThe bitrate (bits per second of audio) and the sampling rate (defines the number of samples or audio signals per second).: To accommodate different use cases, the system should support multiple audio quality settings, from low-resolution for quick previews to high-resolution for professional applications.

  • Multilingual support: The system should be able to generate audio in multiple languages.

Note: We focus on creating a TTS system replicating the human voice. The requirements would change slightly if we wanted to create a system for something else, like generating robotic voices or sound effects.

Nonfunctional requirements

The nonfunctional requirements ensure that the TTS system performs reliably, scales effectively, and maintains security:

  • Scalability: The system must scale to meet increased demand without sacrificing audio quality or response time.

  • Performance: Quick audio generation is essential for real-time applications, such as voice assistants, where immediate feedback is expected.

  • Reliability: The model should consistently produce contextually accurate audio outputs.

  • Availability: The system should be highly available, using redundancy and failover strategies to maintain uptime.

  • Security and privacy: User data, including custom inputs and generated audio, must be handled securely to protect sensitive information and comply with privacy regulations.

Model selection

For our TTS system, we want to select an open-source model with a modern architecture that is generative and has a larger number of trainable parameters for accuracy. Keeping this in view, we will go with a Fish Speech-like model. The Fish Speech base architecture uses an innovative dual autoregressiveAutoregressive (AR) models predict future values in a sequence based on past values. Imagine predicting the next word in a sentence: you'd consider the words you've already read. AR models do this mathematically, using previous data points as input to a regression equation that calculates the next point. They're like having a short-term memory for patterns in data, making them useful for tasks like time series forecasting and sequence generation, such as in speech synthesis. (Dual-AR) structure. It can handle complex linguistic featuresLanguage characteristics include phonetics, syntax, semantics, and prosody, which models must understand and replicate to generate natural and accurate speech., polyphonic wordsWords that have multiple pronunciations depending on their context, such as "read" (present tense vs. past tense) or "lead" (a metal vs. to guide)., and multilingual inputs efficiently. Fish-Speech’s architecture integrates an LLM for linguistic feature extraction, providing streamlined multilingual synthesis.

The Fish Speech TTS architecture
The Fish Speech TTS architecture

The Fish Speech architecturehttps://arxiv.org/html/2411.01156v2 begins with an LLM that processes the input text and extracts linguistic features. These features are fed into a slow transformer, which generates token logitsThe raw output of a language model represents the probabilities of different tokens (words or sub-word units) in the sequence.. The first AR model uses RMSNormA normalization technique used in deep learning to stabilize training and improve performance, particularly in recurrent neural networks. and slow transformer layers to generate hidden states. Another AR model with fast embedding and fast transformer layers uses these hidden states to generate codebook logitsProbabilities over entries in a learned codebook, where each entry represents a small unit of sound.. These logits are then passed to a decoder as quantized mel tokensThese are compact representations of audio information. First, the audio signal is transformed into a mel spectrogram, which captures the sound frequencies similarly to how humans perceive pitch. This mel spectrogram is then quantized, meaning its continuous values are converted into a limited set of discrete values or tokens. This process is similar to reducing the number of colors in an image to create a simpler representation. These tokens are then used by the model to generate speech efficiently..

Finally, these codebook logits produce the output speech waveformThe raw audio signal represents the changes in air pressure over time that we perceive as sound.. This Dual-AR structure allows Fish Speech to effectively model both the linguistic and acoustic aspects of speech, resulting in high-quality and natural-sounding synthesized speech.

In Fish Speech’s architecture, the slow transformer focuses on processing the linguistic features extracted by the LLM. It operates at a slower pace due to the complexity of language modeling. On the other hand, the “fast” transformer handles the acoustic information (mel spectrograms) and operates more quickly to generate the final speech waveform. A Firefly-GAN (FF-GAN) is used as the decoder.

Use the widget below to strengthen your knowledge of the Fish Speech architecture.

AI Powered
Saved
20 attempts left
Reset
You have 20 attempts to answer.

Why use the Fish Speech model?

Fish Speech offers several compelling advantages in text-to-speech synthesis:

  • High-quality speech synthesis: Fish Speech delivers natural and expressive speech with improved prosodyThe rhythm, stress, and intonation patterns in speech convey meaning beyond the literal words, such as emotional tone or emphasis. and phonemeThe smallest unit of sound in speech that can distinguish one word from another, such as the difference between "bat" and "pat." accuracy using modern techniques. The dual-stream processing ensures that the generated speech maintains global coherence and fine acoustic detail, meeting the requirements for high-quality synthesisThe process of generating speech. across different linguistic contexts.

Note: Older TTS systems used long short-term memory models (LSTMs) and basic neural networks. These have been largely replaced by technologies like recurrent neural networks (RNNs) and transformer-based models. This is another reason to choose this architecture over something like NVIDIA’s Tacotron2 (LSTM-based).

  • Efficiency and scalability: Fish Speech demonstrates remarkable efficiency through its optimized codebookA codebook in speech synthesis refers to a collection of predefined sound representations, or codewords, used to compress speech segments. It helps the model efficiently store and retrieve acoustic information, reducing the complexity of generating speech. utilization and reduced inference latency. The model’s modular design allows for scalability, enabling straightforward adaptation to datasets of varying sizes and linguistic complexity.

  • Multilingual capability: Fish Speech excels at handling multilingual inputs due to its integrated LLM feature extraction, which can capture linguistic nuances across diverse languages. This eliminates the need for language-specific preprocessing or additional model components.

  • Parameter size: We will create our model based on Fish Speech’s architecture, containing around 2 billion parameters. That is much larger than any comparative models available today for speech synthesis. We can see the comparison in the table below.

We can see the comparison of modern TTS models in the table below.

Feature

Fish Speech v1

Tacotron 2

xTTS

WaveNet

Parameters

1 B

~50 M

~500 M

~24 M

Multilingual Capability

Native

Limited support

Native

None (language-specific)

Audio Quality (MOS)

~4.05

~4.5

~4.0

~4.2

Open Source?

✅

✅

✅

❌

Limitations

Requires a lot of memory

Requires large datasets to train

Complex architecture

Slow inference

1.

Why do we prefer a model with a large number of trainable parameters?

Show Answer
Did you find this helpful?

Fish Speech provides our multilingual TTS system’s ideal balance of innovation, efficiency, and flexibility.

The training process

Let’s discuss how to train a speech synthesis model like Fish Speech, starting with the dataset.

Data acquisition and preparation

High-quality, well-curated data is crucial for training an effective text-to-speech model. The dataset must include various text-audio pairs to ensure the model can generate natural, expressive, and contextually accurate speech. These pairs should encompass diverse linguistic features such as different speech styles, tones, emotions, accents, and intonations. Additionally, the dataset should cover a broad spectrum of contexts and scenarios, ensuring that the model can adapt to varying speaking conditions and produce realistic and coherent speech in any given situation.

Source of training data

We can create our dataset for this system or use a publicly available dataset like the Common Voice corpus (19.0)https://commonvoice.mozilla.org/en/datasets. Collecting audio data is especially difficult due to its intensive nature. Common Voice, for example, has 3,587 hours of audio data. Recording this would take one person about half a year, not to mention the concerns of language and tonality.

So, we will use the Common Voice datasets to equal around 50,000 hours of data, which should be around 1-2 TB. We will assume 2 TB. According to the Common Voice datasets numbers, this should have around 2 M rows.

Dataset format

For speech generation, we require the dataset to be in the following format:

The required dataset format to train a TTS model
The required dataset format to train a TTS model

Note: Many off-the-shelf datasets will come in formats that may not be suitable for training immediately. We may need to remove or merge some columns (features) to prepare the dataset for training.

Data preprocessing

Before we can move on to training, we need to process the data to ensure consistency. This will involve:

  • Data cleaning: This step involves filtering out low-quality or irrelevant data, such as inaudible or duplicate entries. Inappropriate or offensive content is also removed to maintain ethical standards.

Note: To remove inappropriate or offensive content from the dataset requires an expert review of each recording, and doing that for 2 M rows may be infeasible. If we are using a reputable dataset, we may skip this part.

  • Noise reduction: Removing background noise from audio clips using filters.

  • Standardization: This includes normalizing to a consistent sampling rateThe number of audio samples captured per second, measured in Hertz (Hz). A higher sampling rate captures more detail and allows for a wider range of frequencies. (e.g., 16 kHz) and bit-depthThe number of bits used to represent each audio sample. Higher bit depth allows for a greater dynamic range (the difference between the quietest and loudest sounds) and finer gradations in amplitude. (16-bit) to ensure compatibility during training.

  • Silence trimming: Trimming leading and trailing silences to reduce unnecessary padding in the data.

Then, we need to store this data in some data stores.

Database selection

Like the previous design problem, we can store our data in a simple SQL database and use a blob store for audio file storage.

We can store our processed dataset in a blob store and an SQL database
We can store our processed dataset in a blob store and an SQL database

Time estimation for data processing

Let’s use some approximate values for our dataset:

Assuming:

We get:

So the total time taken is:

Total time=Tpa+Tpt+Ts\text{Total time} = T_{pa} + T_{pt} + T_s ...