自然な音声のためのTTSプロンプトパターン
TTS出力を改善する文構造、句読点、ペース指定を学びます。
「自然な音声のためのTTSプロンプトパターン」はCoddyKit上の無料AI Prompt Engineeringレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAI Prompt Engineering学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 AI Prompt Engineeringコースには全4レッスンが含まれています。
TTSプロンプトが異なる理由
TTSシステムはテキストを文字どおり音声に変換します。読者が分かりにくい部分を読み返せる視覚的なテキストとは異なり、聞き手は音声を直線的に体験し、曖昧な文を一時停止して解読することができません。
TTS向けに書くということは、単語がどのように聞こえるかを考えるということです。リズム、文の長さ、発音の曖昧さ、太字や箇条書きのような視覚的な書式がないことを考慮する必要があります。
文の長さ:短いほどよい
複数の節を含む長く複雑な文は、音声では追いにくくなります。TTSシステムは、文法的には正しくても音声としては不自然な箇所で、リズムを途切れさせることがよくあります。自然に聞こえる音声にするには、1文を10~20語にすることを目指してください。
# Prompt a model to generate TTS-optimized text
TTS_SYSTEM_PROMPT = (
'You are writing text that will be read aloud by a text-to-speech system.\n\n'
'Rules:\n'
'- Use short, clear sentences (10-20 words each).\n'
'- Avoid complex nested clauses.\n'
'- End each sentence with a period for clear pause signals.\n'
'- Avoid parenthetical asides in the middle of sentences.\n'
'- Use conversational vocabulary — write as you would speak.\n'
'- Never use bullet points, headers, or markdown formatting.'
)
# Bad (long, nested):
BAD = (
'The transformer architecture, which was introduced in the landmark 2017 paper '
'"Attention is All You Need" by Vaswani et al. at Google, fundamentally changed '
'natural language processing by replacing recurrence with self-attention.'
)
# Good (TTS-friendly):
GOOD = (
'The transformer architecture changed natural language processing. '
'It was introduced in 2017 by researchers at Google. '
'Their key innovation was replacing recurrence with self-attention.'
)音声の手がかりとしての句読点
TTSエンジンは、句読点を使って話すテンポを調整します。
- ピリオド(.): 文の終止、長めの間
- コンマ(,): 短い間
- 疑問符(?): 上昇イントネーション
- 感嘆符(!): 強調と勢い
- セミコロン(;): エンジンによって動作が異なり、多くの場合は無視される
- エン・ダッシュ(—): 不自然な間が生じやすいため、避ける
テンポを確実に制御するには、エン・ダッシュやセミコロンではなく、明示的なピリオドを使用してください。
TTS_PUNCTUATION_PROMPT = (
'Write the following content for text-to-speech narration. '
'Use only periods, commas, and question marks for punctuation. '
'Avoid em dashes, semicolons, colons, and parentheses. '
'Break complex thoughts into multiple short sentences.\n\n'
'Content to rewrite: {content}'
)
# Example transformation
original = (
'There are three main factors to consider: cost, quality, and speed — '
'and often, you can only optimize for two of them (this is sometimes '
'called the project management triangle).'
)
for_tts = (
'There are three main factors to consider. The first is cost. '
'The second is quality. The third is speed. '
'Usually, you can only optimize for two of these at once. '
'This is sometimes called the project management triangle.'
)
print(for_tts)曖昧な略語を避ける
読者が目で見て補う略語は、TTSで誤発音を招く落とし穴になります。TTSエンジンによって、略語の処理方法は一貫していません。
Dr.→ 「Doctor」と発音する場合もあれば、「Drive」と発音する場合もありますSt.→ 「Saint」または「Street」?vs.→ 「versus」または「vs」?etc.→ 「et cetera」または「etcee」?
正しく発音させるには、TTS用テキストでは略語を正式な綴りで書いてください。
TTS_ABBREVIATION_RULES = (
'When writing for text-to-speech:\n'
'- Write "Doctor" not "Dr."\n'
'- Write "Street" or "Saint" not "St."\n'
'- Write "versus" not "vs."\n'
'- Write "et cetera" not "etc."\n'
'- Write "for example" not "e.g."\n'
'- Write "that is" not "i.e."\n'
'- Write out years: "twenty twenty-five" not "2025" when narrated in prose\n'
'- Write out numbers under 10: "three" not "3" in conversational text\n'
'- Spell out acronyms on first use: '
'"Application Programming Interface, or API"\n'
)
print(TTS_ABBREVIATION_RULES)誤発音を引き起こす単語
特定の単語やパターンは、TTSエンジンで繰り返し問題を起こします。そうした単語を把握し、代替表現を使用してください。
- 同形異義語: 'read'(現在形か過去形か)、'lead'(金属か導くか)、'wind'。TTSはどちらか一方の発音を選びます
- 珍しい固有名詞: 技術用語、ブランド名、外国語
- 特殊な文脈の数字: APIバージョン、日付形式、測定値
# Prompting LLM to detect and fix TTS pronunciation issues
TTS_REVIEW_PROMPT = (
'Review the following text for text-to-speech pronunciation issues.\n'
'Identify words that might be mispronounced by a TTS engine because they:\n'
'1. Are homographs with multiple pronunciations\n'
'2. Are technical terms, brand names, or foreign words\n'
'3. Are abbreviations or acronyms\n'
'4. Are numbers in unusual formats\n\n'
'For each issue, provide the original text and a TTS-safe replacement.\n\n'
'Text to review: {text}'
)
# Example issues and fixes
ISSUES = {
'She read the docs': 'She read (past tense - ambiguous) -> She finished reading the docs',
'Lead developer': 'Lead (metal or guide?) -> Lead (rhymes with feed) developer',
'API v2.3.1': 'v2.3.1 -> version 2 point 3 point 1',
'The .env file': 'dot E N V file (may say .env) -> the environment config file',
'Re-init': 'may say Ray-in-it -> reinitialize',
}
for problem, fix in ISSUES.items():
print(f'Issue: {problem}\nFix: {fix}\n')TTS向けの数字と日付
数字は、TTSで不自然さが生じる主な原因です。どのように発音すべきか曖昧さが残らない形で書いてください。
NUMBER_TTS_RULES = (
'When writing numbers for TTS narration:\n'
'- Dates: write "January fifteenth, 2025" not "01/15/2025"\n'
'- Time: write "3 in the afternoon" not "15:00" in casual speech\n'
'- Percentages: write "forty-five percent" not "45%" in narration\n'
'- Large numbers: write "one point two million" not "1.2M"\n'
'- Phone numbers: spell with hyphens "555-123-4567" (TTS reads each digit)\n'
'- Currency: write "twelve dollars and fifty cents" not "$12.50" in speech\n'
'- Fractions: write "three quarters" not "3/4"\n'
'- Ordinals: write "first" not "1st" (TTS may say "one S T")\n'
)
# Apply when prompting the LLM to generate TTS scripts
TTS_SCRIPT_PROMPT = (
'Write a 30-second product announcement for text-to-speech.\n'
'Product: TaskFlow Pro, $49/month, 10,000 users worldwide, '
'launched January 2025.\n\n'
+ NUMBER_TTS_RULES
)視覚的な書式を取り除く
MarkdownやHTMLの書式は、目で読む分には意識されませんが、一部のTTSエンジンでは読み上げられます。アスタリスク、シャープ記号、山括弧は、削除するか、読み上げる同等の表現に置き換える必要があります。
TTS_FORMAT_CONVERSION_PROMPT = (
'Convert the following markdown text into plain prose suitable '
'for text-to-speech narration.\n\n'
'Rules:\n'
'- Remove all markdown formatting (**, *, #, -, etc.)\n'
'- Convert bullet lists into spoken sequences '
'("First... Second... Third...")\n'
'- Convert headers into topic introduction sentences\n'
'- Remove any hyperlinks or URLs\n'
'- Convert code snippets into descriptions '
'("a Python function that...")\n\n'
'Markdown text:\n'
'{markdown_text}'
)
EXAMPLE_MARKDOWN = (
'## Getting Started\n'
'- Install the package with 'pip install mylib'\n'
'- Set your **API key** in '.env'\n'
'- Run 'python main.py' to start\n'
)
EXAMPLE_TTS = (
'To get started, install the package using pip. '
'Next, set your API key in your environment configuration file. '
'Finally, run the main Python script to start.'
)
print(EXAMPLE_TTS)つなぎのフレーズでペースを調整する
書き言葉では、視覚的な構造(段落や見出し)が読者を導きます。TTS音声では、聞き手が構成を追えるように、言葉によるつなぎのフレーズが必要です。
TRANSITION_PHRASES = {
'starting_new_topic': ['Let us now talk about', 'Moving on to', 'Next,'],
'adding_information': ['Additionally,', 'Also worth noting,', 'Furthermore,'],
'contrasting': ['However,', 'On the other hand,', 'That said,'],
'concluding': ['To summarize,', 'In short,', 'To wrap up,'],
'sequencing': ['First,', 'Second,', 'Then,', 'Finally,'],
'emphasizing': ['Importantly,', 'Keep in mind that', 'Note that'],
}
TTS_STRUCTURE_PROMPT = (
'Write a two-minute explainer on {topic} for text-to-speech narration.\n'
'Use verbal transition phrases to guide listeners through each point. '
'Avoid headers or bullet points. '
'Structure the content with clear spoken signposts '
'("First...", "Moving on...", "To summarize...").'
)
print('Available transitions:')
for category, phrases in TRANSITION_PHRASES.items():
print(f' {category}: {phrases[0]}')TTSテキストをテストする
TTSの品質を確実にテストする唯一の方法は、実際に聞くことです。テストして聞くループを作りましょう。テキストを生成する → TTS APIに送る → 聞く → 改善する。テキストを目で読むだけでは不十分です。
import openai
import pathlib
client = openai.OpenAI(api_key='sk-...')
def generate_and_test_tts(text, output_file='test_audio.mp3'):
"""Generate TTS audio from text for auditory review."""
response = client.audio.speech.create(
model='tts-1-hd',
voice='alloy', # alloy, echo, fable, onyx, nova, shimmer
input=text,
speed=1.0 # 0.25 to 4.0
)
audio_path = pathlib.Path(output_file)
response.stream_to_file(audio_path)
print(f'Audio saved to {audio_path}')
print(f'Text length: {len(text)} chars, {len(text.split())} words')
return audio_path
# Generate and listen before shipping
tts_text = (
'Welcome to our weekly update. '
'This week, the engineering team shipped three major features. '
'First, we improved search speed by forty percent. '
'Second, we added support for twelve new languages. '
'Third, we launched our new mobile application.'
)
path = generate_and_test_tts(tts_text)音声の選択とプロンプトの適合
TTS音声にはそれぞれ異なる強みがあります。コンテンツのトーンに合う音声を選んでください。
- 温かみのある/語り口調: ストーリーテリング、教育コンテンツ
- プロフェッショナル/ニュートラル: ビジネスレポート、技術文書
- エネルギッシュ/明るい: マーケティング、製品デモ、通知
LLMには、音声の自然な語調に合うコンテンツを書くようプロンプトを与えてください。
VOICE_SPECIFIC_PROMPTS = {
'professional': (
'Write in a clear, neutral, professional tone. '
'Use complete sentences. Avoid contractions. '
'Suitable for business reports and documentation.'
),
'warm_narrative': (
'Write in a warm, engaging, conversational tone. '
'Use contractions naturally. '
'Speak directly to the listener using "you" and "we". '
'Suitable for educational content and storytelling.'
),
'energetic': (
'Write in an upbeat, enthusiastic tone. '
'Use shorter sentences for impact. '
'Include emphasis words like "amazing", "incredible", "now". '
'Suitable for marketing and product announcements.'
),
}
# Select based on use case
use_case = 'warm_narrative'
print(VOICE_SPECIFIC_PROMPTS[use_case])LLMからTTSへのパイプライン設計
実運用のパイプラインでは、LLMがテキストを生成し、それをTTSエンジンに渡します。両者を連携させる必要があります。LLMは読み物用ではなくTTS用のテキストを生成していることを理解し、TTS APIに届く前に、システムプロンプトや後処理でTTSに適したルールを適用する必要があります。
LLMの出力とTTS入力の間に軽量な後処理ステップを追加してください。漏れ込んだMarkdownを除去し、略語を展開し、文の長さを確認します。これにより、LLMの書式ミスが音声上の不自然さになる前に検出できます。
理解度チェック:TTSの文構造
次のテキストのうち、音声合成によるナレーションに最も適した形式はどれですか。
まとめ:自然な音声のためのTTSプロンプトパターン
TTSテキストは目ではなく耳のために書く必要があります。主なルールは、文を10~20語に収めること、間を取るにはピリオドとコンマだけを使うこと、すべての略語と数字を正式な形で書くこと、Markdownと視覚的な書式をすべて削除すること、視覚的な構造の代わりに言葉によるつなぎのフレーズを使うことです。同形異義語、技術用語、特殊な数字形式などの単語は誤発音を引き起こすため、検出して置き換えてください。生成された音声は、テキストを読むのではなく、必ず聞いてテストしてください。
よくある質問
「自然な音声のためのTTSプロンプトパターン」レッスンは無料ですか?
はい。「自然な音声のためのTTSプロンプトパターン」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、AI Prompt Engineeringコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 AI Prompt Engineeringコースには全4レッスンが含まれています。
「自然な音声のためのTTSプロンプトパターン」で何を学びますか?
TTS出力を改善する文構造、句読点、ペース指定を学びます。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
AI Prompt Engineeringを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAI Prompt Engineeringは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「自然な音声のためのTTSプロンプトパターン」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAI Prompt Engineeringレッスンでコードを書いて実行できますか?
はい。すべてのAI Prompt Engineeringレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 自然な音声のためのTTSプロンプトパターン
- SSMLと韻律の制御
- Voice AIのペルソナ設計
- マルチモーダル音声・テキストエージェント