πŸ€–AI/ML

TTS

Text-to-Speech / Speech Synthesis

AI technology that converts text into natural-sounding speech. Used in diverse fields such as accessibility, voice assistants, audiobooks, and content narration.

πŸ“– Detailed Explanation

TTS (Text-to-Speech) is a technology that converts written text into speech. It analyzes the input text and generates speech with natural pronunciation, intonation, and rhythm. Modern AI-based TTS uses deep learning to produce speech so natural that it is hard to distinguish from a human voice.

The development of TTS technology can be broadly divided into three generations. The first generation was rule-based synthesis, which produced robot-like speech. The second generation used concatenative synthesis, which joins recorded speech units, and improved naturalness. The third generation is based on deep learning, in which models such as Tacotron, WaveNet, and VITS achieved groundbreaking quality.

Modern TTS systems mainly work in two stages. First, in the text analysis stage, the input text is converted into phonemes and prosody information is predicted. Second, in the speech synthesis stage, a mel spectrogram is generated and a vocoder converts it into an audio waveform. VITS, a recent model, handles this process end-to-end, delivering faster and more natural results.

TTS is widely used in accessibility (screen readers for the visually impaired), voice assistants (Siri, Alexa), audiobook production, call center automated responses, educational content, and AI video (Synthesia). Recently, combined with Voice Cloning technology, it has also become possible to reproduce a specific person's voice.

πŸ’» Code Example

Here are usage examples of various TTS libraries and APIs.

# TTS ν™œμš© 예제 - λ‹€μ–‘ν•œ 방법
import os

# ===== 1. OpenAI TTS API =====
from openai import OpenAI

client = OpenAI()

def openai_tts(text: str, voice: str = "alloy", output_file: str = "speech.mp3"):
    """
    OpenAI TTS API μ‚¬μš©
    voices: alloy, echo, fable, onyx, nova, shimmer
    """
    response = client.audio.speech.create(
        model="tts-1",  # tts-1 (빠름) λ˜λŠ” tts-1-hd (κ³ ν’ˆμ§ˆ)
        voice=voice,
        input=text
    )
    response.stream_to_file(output_file)
    print(f"생성 μ™„λ£Œ: {output_file}")

# μ‚¬μš© μ˜ˆμ‹œ
# openai_tts("μ•ˆλ…•ν•˜μ„Έμš”, KAITRUST AI λ°±κ³Όμ‚¬μ „μž…λ‹ˆλ‹€.", "nova")

# ===== 2. Google Cloud TTS =====
from google.cloud import texttospeech

def google_tts(text: str, language: str = "ko-KR", output_file: str = "output.mp3"):
    """Google Cloud TTS - κ³ ν’ˆμ§ˆ ν•œκ΅­μ–΄ 지원"""
    client = texttospeech.TextToSpeechClient()

    synthesis_input = texttospeech.SynthesisInput(text=text)

    voice = texttospeech.VoiceSelectionParams(
        language_code=language,
        ssml_gender=texttospeech.SsmlVoiceGender.FEMALE
    )

    audio_config = texttospeech.AudioConfig(
        audio_encoding=texttospeech.AudioEncoding.MP3,
        speaking_rate=1.0,  # 0.25 ~ 4.0
        pitch=0.0  # -20.0 ~ 20.0
    )

    response = client.synthesize_speech(
        input=synthesis_input, voice=voice, audio_config=audio_config
    )

    with open(output_file, "wb") as out:
        out.write(response.audio_content)
    print(f"생성 μ™„λ£Œ: {output_file}")

# ===== 3. μ˜€ν”ˆμ†ŒμŠ€ TTS (Coqui TTS) =====
# pip install TTS
from TTS.api import TTS

def coqui_tts(text: str, output_file: str = "coqui_output.wav"):
    """무료 μ˜€ν”ˆμ†ŒμŠ€ TTS - 둜컬 μ‹€ν–‰"""
    # μ‚¬μš© κ°€λŠ₯ν•œ λͺ¨λΈ λͺ©λ‘: TTS.list_models()
    tts = TTS(model_name="tts_models/ko/css10/vits")  # ν•œκ΅­μ–΄ λͺ¨λΈ

    tts.tts_to_file(
        text=text,
        file_path=output_file
    )
    print(f"생성 μ™„λ£Œ: {output_file}")

# ===== 4. Edge TTS (무료, Microsoft) =====
# pip install edge-tts
import edge_tts
import asyncio

async def edge_tts_generate(text: str, voice: str = "ko-KR-SunHiNeural"):
    """Microsoft Edge TTS - 무료, κ³ ν’ˆμ§ˆ"""
    communicate = edge_tts.Communicate(text, voice)
    await communicate.save("edge_output.mp3")
    print("생성 μ™„λ£Œ: edge_output.mp3")

# ν•œκ΅­μ–΄ μŒμ„±: ko-KR-SunHiNeural (μ—¬μ„±), ko-KR-InJoonNeural (남성)
# asyncio.run(edge_tts_generate("μ•ˆλ…•ν•˜μ„Έμš”, ν…ŒμŠ€νŠΈμž…λ‹ˆλ‹€."))

# ===== 5. 비ꡐ ν…Œμ΄λΈ” 좜λ ₯ =====
print("=" * 60)
print("TTS μ„œλΉ„μŠ€ 비ꡐ")
print("=" * 60)
print(f"{'μ„œλΉ„μŠ€':<15} {'λΉ„μš©':<20} {'ν’ˆμ§ˆ':<10} {'ν•œκ΅­μ–΄'}")
print("-" * 60)
print(f"{'OpenAI TTS':<15} {'$15/1M chars':<20} {'우수':<10} {'O'}")
print(f"{'Google TTS':<15} {'$4~16/1M chars':<20} {'μ΅œμƒ':<10} {'O'}")
print(f"{'Edge TTS':<15} {'무료':<20} {'우수':<10} {'O'}")
print(f"{'Coqui TTS':<15} {'무료(둜컬)':<20} {'μ–‘ν˜Έ':<10} {'O'}")

πŸ“Š Performance & Cost

Comparison of Major TTS Services (as of January 2025)

ServicesCostFeaturesKorean
OpenAI TTS$15/1M characters6 voices, fast generationSupported
Google Cloud TTS$4–16/1M charactersWaveNet, Neural2, 400+ voicesHighest quality
Amazon Polly$4–16/1M charactersNTTS, Standard, 60+ languagesSupported
ElevenLabs$5–330/monthVoice cloning, emotional expressionSupported
Edge TTSFreeBased on Microsoft AzureHigh quality
Coqui TTSFree (open source)Runs locally, customizableVITS model

* ElevenLabs: Additional charges apply for voice cloning
* Real-time streaming TTS may incur additional charges

πŸ—£οΈ Say It Like This in Practice

πŸ’¬ In a Meeting
"We're planning to adopt TTS for audiobook automation. For Korean quality, Google Cloud TTS's WaveNet is the most natural, and if you need to cut costs, Edge TTS is usable for free. Google costs about $4–16 per 1 million characters per month."
πŸ’¬ In an Interview
"Modern TTS uses combinations like Tacotron2 + HiFi-GAN or end-to-end models like VITS. Tacotron generates a mel spectrogram from text, and the vocoder converts it into audio. VITS handles this with a single model, so it's faster and more natural."
πŸ’¬ In a Technical Discussion
"For voice cloning, ElevenLabs is the most advanced. It can clone a voice fairly closely even from a 30-second sample. However, cloning a voice without consent can become a legal issue, so you need to be careful."

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

⚠️ Common Mistakes & Cautions

❌
Voice cloning ethics issues
Cloning someone's voice without authorization or using it for fraud creates legal liability. Always obtain the person's consent when using Voice Cloning.
❌
Processing long text all at once
Most TTS APIs have character limits (OpenAI: 4096 characters). Long text must be split into chunks and joined together naturally.
βœ…
Correct approach
1) Control pronunciation, pauses, and emphasis with SSML tags, 2) split into chunks by sentence, 3) reduce the cost of repeated requests through caching, 4) decide on a commercial service after prototyping with a free service.

πŸ”— Related Terms

πŸ“š Learn More