DEV Community

VoiceDeveloper
VoiceDeveloper

Posted on

How to Write Text That Sounds Great When Spoken by AI

Why the Text You Write Matters for AI Voices

When you feed a string into a text‑to‑speech (TTS) engine, the AI doesn’t just read the letters—it tries to infer rhythm, emphasis, and emotion. A poorly‑crafted sentence can sound robotic, choppy, or just plain confusing, even if the underlying model is state‑of‑the‑art.

In voice‑AI projects—whether you’re building a virtual assistant, an audiobook narrator, or a voice‑cloned podcast host—your script is the first (and often most important) piece of the puzzle. The better the script, the more natural the output, and the less you’ll need to spend on post‑processing or manual edits.

Below are practical, developer‑focused guidelines that will help your text sound great when spoken by AI, plus a quick walkthrough of the ElevenLabs API, a leading TTS platform that makes it easy to test these ideas in real time.


1. Keep Sentences Short and Chunked

AI models excel at natural prosody when they can “breathe.” Long, run‑on sentences force the engine to guess where pauses should be, often resulting in monotone delivery.

Good:

The new feature launches tomorrow. It will let users upload photos directly from their phones.
Enter fullscreen mode Exit fullscreen mode

Bad:

The new feature launches tomorrow and it will let users upload photos directly from their phones without any extra steps.
Enter fullscreen mode Exit fullscreen mode

Break complex ideas into bite‑size chunks, and let punctuation do the heavy lifting.


2. Use Punctuation Strategically

  • Commas → short pause, soft emphasis.
  • Periods → full stop, natural breath.
  • Ellipsis (…) → trailing thought, slight hesitation.
  • Exclamation points → higher energy, but don’t overuse.
We’ve detected an anomaly… please check your dashboard.
Enter fullscreen mode Exit fullscreen mode

The AI will translate those cues into timing and pitch changes, making the speech feel more human.


3. Avoid Ambiguous Acronyms and Numbers

TTS engines can mispronounce “API,” “SaaS,” or “2024” if they’re not given phonetic hints. Write them out or use SSML’s <say-as> tag.

<speak>
  The API will be updated in <say-as interpret-as="date">2024-06-01</say-as>.
</speak>
Enter fullscreen mode Exit fullscreen mode

If you’re using a platform that supports SSML (like ElevenLabs), this tiny addition can save you hours of manual tweaking.


4. Leverage SSML for Fine‑Grained Control

Speech Synthesis Markup Language (SSML) lets you adjust pitch, rate, volume, and even insert breaths.

<speak>
  <prosody rate="slow" pitch="+2st">
    Welcome to the future of voice AI.
  </prosody>
  <break time="500ms"/>
  Let’s get started.
</speak>
Enter fullscreen mode Exit fullscreen mode

Most modern TTS services parse SSML automatically. If you’re not sure whether your chosen service supports it, check the docs—ElevenLabs, for example, fully embraces SSML.


5. Test Early, Test Often

Iterative testing is key. A sentence that reads fine on paper can sound off in audio. Set up a quick script that sends your text to the TTS endpoint, downloads the audio, and plays it back automatically.

Python Example with ElevenLabs

import requests

API_KEY = "YOUR_ELEVENLABS_API_KEY"
VOICE_ID = "EXAMPLE_VOICE_ID"
ENDPOINT = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}"

def synthesize(text: str, filename: str = "output.wav"):
    payload = {
        "text": text,
        "model_id": "eleven_monolingual_v1",
        "voice_settings": {"stability": 0.75, "similarity_boost": 0.85},
        "ssml": False,  # set True if you send SSML
    }
    headers = {
        "xi-api-key": API_KEY,
        "Content-Type": "application/json"
    }
    response = requests.post(ENDPOINT, json=payload, headers=headers)
    response.raise_for_status()

    with open(filename, "wb") as f:
        f.write(response.content)
    print(f"Saved to {filename}")

if __name__ == "__main__":
    script = """
    The new dashboard is live. 
    It shows real‑time metrics, so you can react instantly.
    """
    synthesize(script)
Enter fullscreen mode Exit fullscreen mode

Replace YOUR_ELEVENLABS_API_KEY and EXAMPLE_VOICE_ID with values from your ElevenLabs account. Run the script, listen, and tweak the text until it feels right.

Curl Quick Test

curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/EXAMPLE_VOICE_ID" \
  -H "xi-api-key: YOUR_ELEVENLABS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
        "text": "Your AI assistant is ready to help.",
        "model_id": "eleven_monolingual_v1"
      }' \
  --output assistant.wav
Enter fullscreen mode Exit fullscreen mode

Both snippets demonstrate how straightforward it is to spin up a feedback loop with ElevenLabs.


6. Play With Prosody Settings

Most services expose “stability” (how consistent the voice sounds) and “similarity boost” (how closely it matches a reference voice). For scripted content, a higher stability (≈0.8–0.9) yields a smoother, less jittery output. For voice‑cloned characters, crank up similarity boost (≈0.9) to retain the unique timbre.

Experiment with these parameters in the payload shown above—small adjustments can make a big difference in perceived naturalness.


7. Mind the Contextual Flow

When you have a series of sentences, think of them as a paragraph spoken aloud. Avoid abrupt topic switches. Use transition words (“next,” “then,” “finally”) to guide the AI’s intonation.

First, we’ll load the data. Then, we’ll clean it. Finally, we’ll train the model.
Enter fullscreen mode Exit fullscreen mode

The AI will naturally modulate its pitch at each transition, giving listeners a sense of progression.


8. Use Voice Cloning Wisely

If you’re cloning a specific person’s voice, keep the source material consistent in style and tone. The more uniform the training data, the easier it is for the model to reproduce natural prosody. When you feed the cloned voice new scripts, apply the same writing guidelines you’d use for any TTS voice.

ElevenLabs offers a robust cloning workflow that respects these principles, making it a solid choice for developers who need high‑fidelity voice replicas.


9. Automate Quality Checks

For larger projects, consider adding automated checks:

  • Length sanity: Ensure each utterance stays under a reasonable character limit (e.g., 200 chars) to avoid long‑run monotony.
  • Forbidden words: Scan for profanity or brand‑specific terms that shouldn’t appear.
  • Pronunciation dictionary: Generate a small CSV of words that need phonetic overrides and feed it into the TTS engine (ElevenLabs supports custom pronunciation maps).

A simple Python loop can flag problematic sentences before they ever hit the API.

def validate(text):
    if len(text) > 200:
        raise ValueError("Sentence too long")
    # add more checks as needed
Enter fullscreen mode Exit fullscreen mode

10. Keep the Listener in Mind

Finally, always ask yourself: If I were listening to this on a commute or a smart speaker, would I feel engaged? Test on different devices (headphones, phone speakers, car audio) because acoustic environments affect how prosody is perceived.


TL;DR

  • Write short, punctuated sentences.
  • Use SSML for precise control.
  • Test iteratively with a quick API call.
  • Tweak stability and similarity boost for the desired feel.
  • Leverage ElevenLabs for high‑quality synthesis and voice cloning.

Ready to Hear Your Text Come Alive?

Give the workflow above a spin with ElevenLabs—the platform that makes it painless to experiment with SSML, fine‑tune prosody, and even clone voices. Sign up through this link and start generating natural‑sounding speech in minutes:

Try ElevenLabs now!

Happy coding, and may your AI voices always sound just right.

Top comments (0)