0Pricing
AI Prompt Engineering · درس

أنماط مطالبات TTS للكلام الطبيعي

بنية الجمل، وعلامات الترقيم، وإشارات الإيقاع التي تحسّن مخرجات TTS

أنماط مطالبات TTS للكلام الطبيعي درس مجاني في AI Prompt Engineering على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في AI Prompt Engineering، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة AI Prompt Engineering 4 دروس في المجموع.

لماذا تختلف صياغة مطالبات TTS

تحوّل أنظمة تحويل النص إلى كلام نصك إلى صوت حرفيًا. وعلى خلاف النص المرئي، الذي يمكن للقارئ فيه إعادة قراءة الأجزاء المربكة، يختبر المستمع الصوت بالتسلسل ولا يستطيع إيقافه مؤقتًا لفك غموض جملة ملتبسة.

تعني الكتابة لأجل TTS التفكير في كيفية سماع الكلمات — في الإيقاع، وطول الجملة، والالتباس في النطق، وغياب التنسيق المرئي مثل الخط العريض أو النقاط التعدادية.

قِصر الجمل أفضل

يصعب متابعة الجمل الطويلة والمعقدة التي تتضمن عدة جمل فرعية عند الاستماع إليها. وغالبًا ما تقطع أنظمة TTS الإيقاع عند مواضع صحيحة نحويًا لكنها غير مريحة صوتيًا. استهدف جملًا تتكون من 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 البرمجية → استمع إليه → كرر العملية. لا تعتمد على قراءة النص بصريًا.

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 قبل وصوله إلى واجهة TTS البرمجية.

أضف خطوة معالجة لاحقة خفيفة بين مخرجات LLM ومدخلات TTS: أزل أي Markdown تسرب إلى النص، ووسّع الاختصارات، وتحقق من طول الجمل. تلتقط هذه الخطوة أخطاء تنسيق LLM قبل أن تتحول إلى عيوب صوتية.

اختبار المعرفة: بنية جمل TTS

أي النصوص التالية مُنسّق على أفضل نحو للسرد باستخدام تحويل النص إلى كلام؟

مراجعة: أنماط مطالبات TTS للكلام الطبيعي

يجب كتابة نص TTS للأذن، لا للعين. القواعد الأساسية: اجعل الجمل تتكون من 10 إلى 20 كلمة، واستخدم النقاط والفواصل فقط لضبط الإيقاع، واكتب جميع الاختصارات والأرقام كاملة، وأزل كل Markdown والتنسيق المرئي، واستخدم عبارات انتقال منطوقة بدلًا من الهيكل المرئي. تسبب الكلمات المتجانسة كتابةً، والمصطلحات التقنية، وصيغ الأرقام غير المعتادة نطقًا خاطئًا، لذا اكتشفها واستبدلها. اختبر دائمًا النص بالاستماع إلى الصوت الناتج، لا بقراءة النص.

الأسئلة الشائعة

هل درس «أنماط مطالبات TTS للكلام الطبيعي» مجاني؟

نعم — نص درس «أنماط مطالبات TTS للكلام الطبيعي» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة AI Prompt Engineering، انتقل إلى CoddyKit PRO. تتضمن دورة AI Prompt Engineering 4 دروس في المجموع.

ماذا ستتعلم في «أنماط مطالبات TTS للكلام الطبيعي»؟

بنية الجمل، وعلامات الترقيم، وإشارات الإيقاع التي تحسّن مخرجات TTS تتمرن على AI Prompt Engineering مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ AI Prompt Engineering؟

لا تُشترط خبرة سابقة. AI Prompt Engineering على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «أنماط مطالبات TTS للكلام الطبيعي»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس AI Prompt Engineering هذا؟

نعم. كل درس في AI Prompt Engineering يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. أنماط مطالبات TTS للكلام الطبيعي
  2. التحكم في SSML والتنغيم
  3. تصميم شخصية الذكاء الاصطناعي الصوتية
  4. الوكلاء متعددو الوسائط للصوت والنص
← العودة إلى AI Prompt Engineering