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.
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.
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.
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'}")
Comparison of Major TTS Services (as of January 2025)
| Services | Cost | Features | Korean |
|---|---|---|---|
| OpenAI TTS | $15/1M characters | 6 voices, fast generation | Supported |
| Google Cloud TTS | $4β16/1M characters | WaveNet, Neural2, 400+ voices | Highest quality |
| Amazon Polly | $4β16/1M characters | NTTS, Standard, 60+ languages | Supported |
| ElevenLabs | $5β330/month | Voice cloning, emotional expression | Supported |
| Edge TTS | Free | Based on Microsoft Azure | High quality |
| Coqui TTS | Free (open source) | Runs locally, customizable | VITS model |
* ElevenLabs: Additional charges apply for voice cloning
* Real-time streaming TTS may incur additional charges
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free