# How ElevenLabs Handles Emotion and Prosody in Speech

> Source: <https://dev.to/voice_developer/how-elevenlabs-handles-emotion-and-prosody-in-speech-j8>
> Published: 2026-10-25 00:02:39+00:00

If you’ve ever played with text‑to‑speech (TTS) APIs, you know the difference between a robotic monotone and a voice that actually feels human. The secret sauce is **emotion and prosody** – the subtle variations in pitch, rhythm, and intensity that convey meaning beyond the words themselves. In this article we’ll explore how modern voice‑AI platforms model these nuances and walk through a practical example using **ElevenLabs** – a service that lets you generate expressive speech with just a few lines of code.

**TL;DR:** ElevenLabs’ API gives you fine‑grained control over emotion, style, and prosody, and you can start experimenting in minutes with the Python snippet below.

When we speak, we naturally modulate:

| Aspect | What it does | Example | 
|---|---|---|
| **Pitch** | Raises or lowers the voice | Question vs. statement | 
| **Rate** | Speeds up or slows down | Excitement vs. calm | 
| **Volume** | Emphasizes important words | Highlighting a warning | 
| **Timbre** | Adds warmth or harshness | Friendly vs. authoritative | 

If a TTS engine ignores these cues, the output feels flat and can even change the perceived intent of the text. For applications like virtual assistants, audiobooks, or interactive games, expressive speech is no longer a luxury – it’s a requirement.

ElevenLabs builds on a deep‑learning backbone that predicts **prosodic contours** conditioned on three main inputs:

The model learns a latent representation of how humans naturally vary pitch and timing. During training it ingests thousands of hours of recorded speech, aligning phonemes with acoustic features. The result is a **prosody encoder** that can be steered at inference time.

ElevenLabs exposes a small set of high‑level emotion tags. Internally these tags bias the latent space toward patterns typical of that emotion. For example, the *excited* tag will push the pitch upward and increase the speaking rate, while *calm* does the opposite.

For developers who need more precision, ElevenLabs supports a subset of **Speech Synthesis Markup Language (SSML)**. You can wrap words in `<prosody>` tags to tweak `rate`, `pitch`, and `volume` on a per‑word basis.

Below is a minimal script that:

``` python
import os
import requests

# -------------------------------------------------
# 1️⃣  Set up your credentials
# -------------------------------------------------
API_KEY = os.getenv("ELEVENLABS_API_KEY")  # store securely!
VOICE_ID = "EXAVITQu4vr4xnSDxMaL"           # default "Rachel" voice

# -------------------------------------------------
# 2️⃣  Build the request payload
# -------------------------------------------------
payload = {
    "text": "Congratulations! You've just unlocked a new achievement.",
    "voice_settings": {
        "stability": 0.75,   # smoothness of the voice
        "similarity_boost": 0.85
    },
    "model_id": "eleven_monolingual_v1",   # latest model
    "emotion": "excited"                  # ← emotion tag
}

headers = {
    "xi-api-key": API_KEY,
    "Content-Type": "application/json"
}

# -------------------------------------------------
# 3️⃣  Call the TTS endpoint
# -------------------------------------------------
url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}"
response = requests.post(url, json=payload, headers=headers)

# -------------------------------------------------
# 4️⃣  Save the audio file
# -------------------------------------------------
if response.status_code == 200:
    with open("output.wav", "wb") as f:
        f.write(response.content)
    print("✅ Audio saved as output.wav")
else:
    print("❌ Error:", response.status_code, response.text)
```

**Pro tip:** Swap `"excited"` for `"sad"` or `"calm"` to hear the same sentence in a completely different mood. You can also adjust `stability` and `similarity_boost` to make the voice sound more “human‑like” or more “synthetic” depending on your use‑case.

Sometimes you need a single word to pop. ElevenLabs lets you embed SSML directly in the `text` field:

```
payload["text"] = """
  <speak>
    The <prosody rate="fast" pitch="+5%">deadline</prosody> is tomorrow.
  </speak>
"""
```

The API will parse the tags and apply the requested rate and pitch only to the word *deadline*. This works great for:

If you’re just testing from the terminal, curl does the heavy lifting:

```
curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/${VOICE_ID}" \
  -H "xi-api-key: $ELEVENLABS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
        "text": "Welcome back, hero. Your journey continues.",
        "emotion": "mysterious",
        "voice_settings": {
          "stability": 0.65,
          "similarity_boost": 0.9
        }
      }' --output hero.wav
```

Replace `mysterious` with any supported emotion label. The resulting `hero.wav` can be dropped straight into a Unity project or a web page.

| Concern | Recommendation | 
|---|---|
| **Latency** | Cache the audio for repeated phrases; ElevenLabs returns a `request_id` that you can use to retrieve a stored file later. | 
| **Concurrency** | Use a queue (e.g., RabbitMQ) to throttle requests if you expect bursts. The free tier allows ~10 RPS; paid plans go much higher. | 
| **Cost** | Track `character_count` in the response payload. Budget per‑month based on expected script length. | 
| **Security** | Keep your API key out of client‑side code. Proxy calls through your backend or a serverless function. | 

You can try it yourself right now by signing up through the affiliate link: **[ElevenLabs](https://try.elevenlabs.io/kr07zfuqn1bp)**. The sign‑up process grants you free credits, so you can experiment without any immediate cost.

Emotion and prosody are the missing pieces that turn a bland robot voice into a compelling conversational partner. By leveraging a prosody encoder, emotion conditioning, and SSML, ElevenLabs gives developers the tools to create speech that feels natural and context‑aware.

Whether you’re building a voice‑enabled chatbot, an immersive game narrator, or an automated podcast generator, the steps above should get you from “Hello, world!” to “Hello, world with feeling.”

**Ready to add genuine emotion to your next project?** Give ElevenLabs a spin today: **[try ElevenLabs here](https://try.elevenlabs.io/kr07zfuqn1bp)** and let your applications speak with personality. Happy coding!
