How does SSML control how a voice agent speaks?
- Authors
- Name
- Amit Shekhar
- Published on
SSML controls how a voice agent speaks by wrapping the reply text in tags that tell the text-to-speech engine where to pause, how fast to talk, which word to stress, and how to read things like dates, numbers, and tricky names.
In this blog, we will learn about how SSML controls how a voice agent speaks. We will also see why plain text is not enough for a voice agent, how the main SSML tags control pauses, speed, stress, and pronunciation, where SSML fits inside a voice agent, who writes the tags, how SSML works with streaming, and where it works well and where it fails.
We will cover the following:
- What is SSML?
- Why plain text is not enough
- How an SSML document looks
- Adding pauses with break
- Controlling speed, pitch, and volume with prosody
- Stressing a word with emphasis
- Reading numbers and dates with say-as
- Fixing pronunciation with phoneme and sub
- Putting the tags together
- Where SSML fits in a voice agent
- Who writes the SSML: our code or the LLM
- SSML and streaming
- Where SSML works well and where it fails
I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.
I teach AI and Machine Learning at Outcome School.
Let's get started.
What is SSML?
SSML (Speech Synthesis Markup Language) is a standard way to add instructions to text, so that a text-to-speech engine knows not only what to say, but also how to say it.
It is a standard from the W3C (World Wide Web Consortium), the group that creates many of the standards for the web. Version 1.0 came in 2004 and version 1.1 came in 2010.
Let's understand the term Markup. Markup means adding tags around normal text to give it extra meaning. In HTML, we write <b>Hello</b> and the browser shows "Hello" in bold. In SSML, we write tags around the text, and the text-to-speech engine changes the way it speaks that text.
A text-to-speech engine, also called a TTS engine, is the part that turns written text into spoken audio. In a voice agent, it is the voice that the caller hears.
So, HTML tells the browser how the text must look, and SSML tells the TTS engine how the text must sound.
Why plain text is not enough
When we give plain text to a TTS engine, the engine has to guess many things on its own.
Let's say our voice agent has to say the following:
Your order 1234 will arrive on 03/04/2026. Please call us at 1800 555 0199.
The engine has to make several guesses here:
- Is "1234" read as "one thousand two hundred thirty-four" or as "one two three four"?
- Is "03/04/2026" the 3rd of April or the 4th of March?
- Is the phone number read slowly digit by digit, or read as one huge number?
- Where does the agent take a short pause so that the caller can follow?
This step of turning written things like numbers, dates, and short forms into spoken words is called text normalization. We have a detailed blog on how a voice agent handles structured inputs like dates, numbers, and addresses that explains this step by step.
Most of the time, the engine guesses well. But in a phone call, one wrong guess is a real problem. If the caller hears the wrong date, the caller waits for the order on the wrong day.
If the phone number is rushed, the caller cannot write it down.
Here comes SSML into the picture. Instead of letting the engine guess, we tell it exactly what to do.
How an SSML document looks
An SSML document is plain text wrapped inside a <speak> tag. As per the standard, every SSML document starts with <speak> and ends with </speak>.
The simplest SSML looks like below:
<speak>
Hello, thank you for calling.
</speak>
Here, we have wrapped our sentence inside the <speak> tag. This alone does not change anything in the voice. It only tells the engine that the text inside can contain SSML tags.
Now, let's add instructions inside it. The most common tags are:
<break>for pauses<prosody>for speed, pitch, and volume<emphasis>for stressing a word<say-as>for reading numbers, dates, and digits<phoneme>and<sub>for pronunciation
Adding pauses with break
The <break> tag adds a pause in the speech.
A human agent naturally pauses after giving important information, so that the caller can take it in. Without pauses, a voice agent sounds rushed.
We can add a pause as below:
<speak>
Your appointment is confirmed. <break time="500ms"/> Is there anything else I can help you with?
</speak>
Here, we have added a pause of 500 milliseconds, which is half a second, after "Your appointment is confirmed." The caller gets a moment to hear the confirmation before the next question comes. The / at the end of the tag means it has no closing tag, because a pause wraps no text.
We can also set the pause by strength instead of exact time as below:
<break strength="strong"/>
Here, the engine decides the exact length based on the strength. The strength values are none, x-weak, weak, medium, strong, and x-strong.
Controlling speed, pitch, and volume with prosody
The <prosody> tag controls how fast, how high, and how loud the voice speaks.
Prosody is the rhythm, speed, and melody of speech. Good prosody makes a voice sound natural instead of flat and robotic.
The three most used attributes are:
ratefor speedpitchfor how high or low the voice soundsvolumefor how loud the voice is
Let's say our agent is reading out a reference number. We want it slower than normal, so that the caller can write it down. We can write the code as below:
<speak>
Your reference number is
<prosody rate="slow">A B 7 2 9</prosody>.
</speak>
Here, only the reference number is spoken slowly. The rest of the sentence stays at normal speed.
We can also use percentages and fixed labels together as below:
<prosody rate="90%" pitch="+5%" volume="loud">
Thank you for your patience.
</prosody>
Here, the voice speaks at 90 percent of its normal speed, 5 percent higher in pitch, and louder than normal. The rate also accepts fixed labels from x-slow to x-fast, like the slow that we used above.
Planning your move into AI?
No matter which tech domain you work in today, with your effort, you can transition to these roles:
- AI Engineer
- Forward Deployed Engineer
- AI Agent Engineer
- Harness Engineer
- Voice AI Engineer
- AI Architect
- LLM Engineer
- LLM Inference Engineer
- Gen AI Engineer
- MLOps Engineer
- ML Engineer
- Deep Learning Engineer
Our AI and Machine Learning Program at Outcome School takes you there.
Stressing a word with emphasis
The <emphasis> tag tells the engine to stress a word, the way we stress a word when we want someone to notice it.
Consider the sentence "Please do not share your PIN with anyone." The most important word is "not". We can write the code as below:
<speak>
Please do <emphasis level="strong">not</emphasis> share your PIN with anyone.
</speak>
Here, the engine says "not" with more force. The levels are strong, moderate, reduced, and none.
The exact effect of emphasis depends on the engine. An engine can make the word louder, slower, or higher in pitch.
Reading numbers and dates with say-as
The <say-as> tag tells the engine what kind of text it is reading, so that it reads it the right way.
This is the tag that solves the problems we saw earlier with "1234" and "03/04/2026". It gives the answer to the engine, so that text normalization does not have to guess.
Let's see the code for the order number first:
<speak>
Your order number is <say-as interpret-as="characters">1234</say-as>.
</speak>
Here, interpret-as="characters" tells the engine to read each character one by one. So, the caller hears "one two three four" instead of "one thousand two hundred thirty-four".
Now, let's fix the date:
<speak>
Your order will arrive on <say-as interpret-as="date" format="dmy">03/04/2026</say-as>.
</speak>
Here, format="dmy" means day, month, year. So, the engine reads it as the 3rd of April 2026, and not the 4th of March.
Some common values of interpret-as are:
cardinalfor normal numbers, like "forty-two"ordinalfor positions, like "second" or "third"charactersfor reading letter by letter or digit by digitdatefor datestelephonefor phone numbers
Note: The SSML standard defines the say-as tag, but the list of supported interpret-as values is not fixed by the main standard. Different TTS engines support different values, so we must check the documentation of the engine we use.
A quick note for you
No matter which tech domain you work in, get familiar with these topics:
- LLM
- RAG
- MCP
- Agent
- Fine-tuning
- Quantization
We put it all together in one video:
AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization
No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.
Now, let's get back to the topic.
Fixing pronunciation with phoneme and sub
Sometimes the engine reads a word wrongly. This happens a lot with names of people, cities, brands, and short forms.
SSML gives us two tags to fix this.
The <sub> tag, short for substitute, replaces the written text with a different spoken text as below:
<speak>
Welcome to <sub alias="Outcome School">OS</sub>.
</speak>
Here, the text shows "OS", but the engine says "Outcome School".
The <phoneme> tag gives the exact sounds of a word. A phoneme is the smallest unit of sound in a language. For example, the word "cat" has three sounds: "k", "a", and "t".
We can write the code as below:
<speak>
You can say <phoneme alphabet="ipa" ph="təˈmɑːtoʊ">tomato</phoneme>.
</speak>
Here, alphabet="ipa" means we are using the International Phonetic Alphabet, which is a standard set of symbols where each symbol stands for one sound. The ph attribute holds the exact sounds. So, the engine says "to-mah-to" instead of "to-may-to".
This is how a voice agent can say the name of a caller correctly.
We have a detailed blog on how pronunciation dictionaries fix how TTS says names and brands that explains how to write these rules once and apply them to every reply.
Putting the tags together
Now, let's combine these tags into one reply from a voice agent. We can write the SSML as below:
<speak>
Hi <phoneme alphabet="ipa" ph="ˈkaːvjə">Kavya</phoneme>, your booking is confirmed.
<break time="400ms"/>
Your booking ID is <say-as interpret-as="characters">BK72</say-as>,
and your visit is on <say-as interpret-as="date" format="dmy">27/10/2026</say-as>.
<break time="300ms"/>
Please <emphasis level="strong">do not</emphasis> forget to bring your ID card.
</speak>
Here, we can see that:
- The name of the caller is said with the exact sounds.
- There are short pauses between the parts.
- The booking ID is read letter by letter and digit by digit.
- The date is read as the 27th of October 2026.
- The words "do not" are stressed, so that the caller does not miss the reminder.
Where SSML fits in a voice agent
A typical voice agent has three main parts: speech-to-text, which turns the caller's voice into text, then the LLM, which writes the reply, and then text-to-speech, which turns the reply into voice.
SSML sits between the LLM and the TTS engine, as in the diagram below:
+-------------------+
| Caller speaks |
+-------------------+
↓
+-------------------+
| Speech-to-text |
+-------------------+
↓
+-------------------+
| LLM writes reply |
+-------------------+
↓
+-------------------+
| Add SSML tags |
+-------------------+
↓
+-------------------+
| TTS engine |
+-------------------+
↓
+-------------------+
| Caller hears |
+-------------------+
Here, we can see that the reply from the LLM is turned into SSML before it reaches the TTS engine. The caller never hears the tags, only their effect.
We have a detailed blog on how to design a real-time voice AI agent that covers this whole pipeline end to end.
Who writes the SSML: our code or the LLM
Now, the question is: who adds these tags? There are two ways.
Way 1: Our code adds the tags.
The LLM writes plain text. Then, our code finds things like dates, phone numbers, and order IDs in that text and wraps them in the right tags.
Let's see the code for this:
import re
def add_ssml(text):
# mark phone numbers, so that they are read as phone numbers
text = re.sub(
r"(\d{4} \d{3} \d{4})",
r'<say-as interpret-as="telephone">\1</say-as>',
text,
)
# add a short pause between sentences
text = text.replace(". ", '. <break time="300ms"/> ')
return f"<speak>{text}</speak>"
reply = "Please call us at 1800 555 0199. We are open all day."
print(add_ssml(reply))
Here, we have:
- Found the phone number pattern (4 digits, 3 digits, 4 digits) and wrapped it in a
say-astag. - Added a pause of 300 milliseconds between sentences.
- Wrapped the whole text inside
<speak>.
It will print the following:
<speak>Please call us at <say-as interpret-as="telephone">1800 555 0199</say-as>. <break time="300ms"/> We are open all day.</speak>
Advantage: It is predictable. The same input always gives the same output.
Disadvantage: It only handles the patterns that we have written rules for.
Way 2: The LLM writes the tags.
We tell the LLM in the system prompt to write SSML directly. For example: "Wrap every phone number in a say-as tag and add a short break after important information." Then, the LLM replies with text that already has the tags inside it, like Call us at <say-as interpret-as="telephone">1800 555 0199</say-as>.
Advantage: The LLM understands the meaning of the reply, so it can stress the right word or pause at the right place.
Disadvantage: The LLM can do mistakes. It can forget to close a tag or invent a tag that the engine does not support. A broken tag can make the engine fail or read the tag out loud.
We can also combine both ways. The LLM writes plain text, our code adds the tags for numbers, dates, and phone numbers, and our code also checks that the final SSML is valid before sending it to the engine.
Note: SSML is written in XML, which is the same tag style that HTML uses, so characters like & and < inside the reply have a special meaning. Our code must escape them in the plain text from the LLM, which means replacing & with & and < with <, before adding tags. Otherwise, a reply like "Tom & Jerry" breaks the SSML.
To learn Prompt Engineering and how to Design a Real-Time Voice AI Agent in depth, check out our AI and Machine Learning Program at Outcome School.
SSML and streaming
A voice agent does not wait for the full reply before speaking. It streams. The LLM sends the reply in small pieces, and the TTS engine starts speaking as soon as the first sentence is ready. This keeps the delay low.
But SSML tags need an opening and a closing. If a piece is cut in the middle of a tag, the engine receives broken SSML.
Let's say the LLM writes the tags, and its output arrives in these two pieces:
Piece 1: Call us at <say-as interpret-as="tele
Piece 2: phone">1800 555 0199</say-as>.
Piece 1 alone is broken, because the say-as tag is cut in the middle. The engine cannot understand it.
So, how can we solve this? The answer is: our code holds the text until a tag is complete. It sends text to the TTS engine only at a safe point, like the end of a sentence where every tag is closed.
Let's see the code for a safe-point check:
def is_safe_to_send(buffer):
# no tag is cut in the middle
if buffer.count("<") != buffer.count(">"):
return False
# every say-as tag that is opened is also closed
if buffer.count("<say-as") != buffer.count("</say-as>"):
return False
# we are at the end of a sentence
return buffer.rstrip().endswith((".", "?", "!"))
Here, we add every incoming piece to a buffer and then call is_safe_to_send. When it returns True, we wrap the buffer in its own <speak> tag, send it to the TTS engine, and start a new buffer. For the two pieces above, the check fails after Piece 1 and passes after Piece 2.
Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.
Where SSML works well and where it fails
SSML works well when:
- We need numbers, dates, phone numbers, and IDs read the same way every time.
- We need a specific name or brand said correctly.
- We need clear pauses so that the caller can follow important information.
- We use a TTS engine that supports the SSML tags we need.
SSML falls short when:
- The TTS engine does not support a tag. Support differs from engine to engine, and many newer TTS models support only a small part of SSML, or none of it.
- We want emotions like happy, calm, or sorry. The standard SSML has no tag for emotion. Some engines add their own extra tags for this, but those tags work only on that engine.
- We use too many tags. A reply full of pauses and speed changes sounds choppy, and the rules become hard to maintain.
Many newer TTS models take a different path. Instead of tags, they accept a plain text instruction like "say this in a calm and warm voice", and the model decides the pauses, speed, and stress on its own. SSML gives exact control, and these models give natural speech with less control. We must choose based on our use case.
Now we must have understood how SSML controls how a voice agent speaks, from the tags themselves to where they fit in a voice agent and where they reach their limits.
Frequently Asked Questions
Can every TTS engine read SSML?
No. Support for SSML differs from engine to engine. Many newer TTS models support only a small part of SSML, or none of it, and the list of supported interpret-as values also changes from engine to engine. So, we must check the documentation of the TTS engine we use before we depend on a tag.
Can SSML make a voice agent sound happy or sorry?
No. The standard SSML has no tag for emotion. Some engines add their own extra tags for emotions like happy, calm, or sorry, but those tags work only on that engine. Many newer TTS models instead accept a plain text instruction like "say this in a calm and warm voice".
What happens if the LLM writes broken SSML?
A broken tag can make the TTS engine fail or read the tag out loud. The LLM can forget to close a tag or invent a tag that the engine does not support. So, our code must check that the final SSML is valid before sending it to the engine.
Does the caller hear the SSML tags?
No. The caller never hears the tags, only their effect. The reply from the LLM is turned into SSML before it reaches the TTS engine, and the engine uses the tags to decide where to pause, how fast to talk, which word to stress, and how to read numbers and names.
That's it for now.
Thanks
Amit Shekhar
Founder @ Outcome School
You can connect with me on:
Follow Outcome School on:
