Speech to Text and Text to Speech for Agents
30-second answer
A voice agent is a loop you can swap piece by piece: speech to text turns the caller into words, the model or agent answers, and text to speech with a neural voice speaks the reply. SSML controls pauses, rate and pitch. When domain words come out wrong, try a phrase list first (no training). For many terms, accents or noisy lines, train a custom speech model and use its endpoint ID. For a live phone agent, Voice Live runs speech in, the model or agent, and speech out over one low-latency connection with noise suppression and turn detection built in.
Simulate it » No Azure account neededExam objective: 4.2.1 Implement workflows to convert speech to text and text to speech for agentic interactions. 4.2.2 Integrate speech as an agent modality, including custom speech models. (Skills measured as of April 16, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Open <strong>Foundry Tools → Azure Speech</strong>. Speech is how an agent hears and talks.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Open Foundry Tools → Azure Speech. Speech is how an agent hears and talks.
- Transcribe a pharmacy call. The base model trips on Metformin and Atorvastatin, and the agent would act on the wrong words.
- In Custom speech, upload related text or labelled audio, train, test, then deploy an endpoint.
- In code, set endpoint_id to use the custom model, or add a PhraseListGrammar to boost a handful of words.
- The reply goes out through text to speech. SSML adds a pause and slows the time so callers catch it.
- For a live phone agent, Voice Live runs speech in, the model or agent, and speech out over one low-latency connection, with noise suppression and turn detection built in.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
A voice for the agent
Speech to text turns the caller into words, the agent answers, and text to speech with a neural voice speaks the reply. SSML controls pauses and rate. A phrase list boosts a few words; custom speech is for many terms, accents or noise. Voice Live runs the loop over one low-latency connection.
🤔 What happens if…
Read this tour as text
- Entities and strict JSON. A support ticket goes to Azure Language for named entities (fixed categories, confidence scores) or to a model deployment that can return any shape you ask for. A model needs a JSON schema with strict: true before code can trust the fields. JSON mode only promises valid JSON.
- Domain summaries and custom extraction. A plain summary drops what an auditor needs. A domain prompt (role, checklist, glossary, one worked example, temperature 0) fixes that without training. For the same fields at high volume, custom named entity recognition in Azure Language learns your own entity types from labelled examples.
- Sentiment and tone. Sentiment analysis returns positive, neutral, negative or mixed with confidence scores, and opinion mining ties each opinion to its target. It is cheap and steady, but it reads “Oh great, another hour on hold” as positive. For tone, ask a model for a label from an enum.
- Safety, PII and Prompt Shields. Content Safety scores Hate, Sexual, Violence and Self-harm at severity 0, 2, 4 or 6 and you choose the block threshold. PII detection can redact only the categories your policy lists. Prompt Shields checks the user prompt and any document for hidden instructions.
- Translator or an LLM. Azure Translator returns many target languages in one fast call, per character. A dynamic dictionary or Custom Translator protects brand names. An LLM translation flow follows tone and formatting rules written in plain words, but it costs more and can vary, so evaluate it first.
- A voice for the agent. Speech to text turns the caller into words, the agent answers, and text to speech with a neural voice speaks the reply. SSML controls pauses and rate. A phrase list boosts a few words; custom speech is for many terms, accents or noise. Voice Live runs the loop over one low-latency connection.
- Translate speech and reason over audio. Speech translation recognises one spoken language and returns text in several in one pass, and can speak the result. When the question is about how something was said, send the audio to an audio-capable model such as gpt-4o-audio-preview. A text-only deployment rejects input_audio.
Contoso Pharmacy wants a phone agent: it listens, answers and speaks back. Then it has to handle Hindi callers and let supervisors ask questions about recorded calls. Build the speech loop, fix misheard drug names, translate speech and send audio to an audio-capable model.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
The phone agent mishears drug names and sounds like a robot reading numbers.
😊 THE SOLUTION
Use a phrase list or custom speech for the vocabulary and SSML for the delivery.
- A few words misheard✓ A phrase list
- Many terms, accents or noisy lines✓ A custom speech model and endpoint ID
- Flat, rushed replies✓ SSML with breaks and prosody
- Slow, stitched-together voice loop✓ Voice Live
Start with a question
What happens if the pharmacy agent hears 'met for men' instead of Metformin?
Contoso Pharmacy wants a phone agent. A caller says, “I need a refill of Metformin 500.” The speech model hears “met for men 500”. The agent looks for a drug that doesn’t exist, apologises, and the caller hangs up.
Nothing is wrong with the agent’s brain. The mistake happened one step earlier, at the ears, and every later step inherited it. A voice agent is only as good as its speech in and speech out.
Explain it like I’m 10
The technical explanation
The voice loop
- Speech to text (Azure Speech): real-time recognition of the caller’s audio.
- Model or agent: reads the text and answers.
- Text to speech: a neural voice such as
en-IN-NeerjaNeuralspeaks the answer.
import azure.cognitiveservices.speech as speechsdk
cfg = speechsdk.SpeechConfig(subscription=KEY, endpoint=ENDPOINT)
cfg.speech_synthesis_voice_name = "en-IN-NeerjaNeural"
recognizer = speechsdk.SpeechRecognizer(cfg, speechsdk.audio.AudioConfig(filename="question.wav"))
heard = recognizer.recognize_once().text
reply = ask_agent(heard)
speechsdk.SpeechSynthesizer(cfg).speak_text_async(reply).get()
Domain words: phrase list or custom speech
| Phrase list | Custom speech | |
|---|---|---|
| Best for | A handful of names and terms | Many terms, accents, noisy lines, industry vocabulary |
| Data needed | None | Related text and/or audio with human-labelled transcripts |
| Training | None | Train, test, deploy an endpoint |
| In code | PhraseListGrammar.addPhrase("Metformin") | cfg.endpoint_id = "<custom endpoint ID>" |
Start with the phrase list. Move to custom speech when the list stops helping.
Shape the voice with SSML
Plain text uses the voice’s defaults. SSML is XML that controls the delivery:
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-IN">
<voice name="en-IN-NeerjaNeural">
Your Metformin is ready <break time="300ms"/>
<prosody rate="-10%">after 5 PM.</prosody>
</voice>
</speak>
Use <break> for pauses, <prosody> for rate and pitch, and the voice’s style options where supported. SSML changes how the answer sounds. It never fixes what was heard.
Voice Live for live agents
Stitching three calls together adds delay and makes interruptions awkward. Voice Live exposes a single real-time connection: audio goes in, a model (such as gpt-4.1-mini) or a Foundry agent answers, and audio comes back out. It includes noise suppression, echo cancellation and end-of-utterance (turn) detection. Choose it for phone agents, kiosks and anywhere a pause of a second feels wrong.
Architect level Why recognition errors travel so far
An agent has no ears of its own. It only sees the transcript. If the transcript is wrong, the agent can be completely confident and completely wrong. That’s why teams measure word error rate on their own recordings, test the hard vocabulary first, and keep a confirmation step (“Did you say Metformin 500?”) for actions that matter, like refills or payments.
Real-world business scenario
Contoso Pharmacy (fictional)
- The problem
- Refill calls overloaded the counter after 5 PM, and a trial voice bot misheard drug names and sounded rushed when it read pickup times.
- What they used
- Azure Speech with a phrase list for the 40 most common drug names, a custom speech model trained on labelled call audio for the full catalogue, SSML replies with a pause before the time, and Voice Live in front of a Foundry agent.
- Why that choice
- The phrase list was the quick fix during the pilot. Custom speech handled the long tail and local accents. SSML made times easy to catch, and Voice Live cut the lag between turns.
- The result
- Most refill calls were completed without staff, and the team added a spoken confirmation for the drug and strength.
When to use it and when not to
✓ Use it when…
- An agent must talk to people on a phone, kiosk or smart speaker.
- Domain names are misrecognised (phrase list first, then custom speech).
- Replies include times, numbers or codes that need careful delivery (SSML).
✕ Think twice when…
- You train custom speech to fix two words.
- You expect SSML to correct what the recogniser heard.
- You act on a spoken request that costs money or health without a confirmation.
↔ Alternatives to consider
- Voice Live for natural, low-latency live conversations.
- Batch transcription for recorded calls you process later.
- A text chat agent when speech adds nothing for the user.
Test yourself with exercises
5 original practice questions in the AI-103 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner How does a voice agent work?
Model answer
Speech to text turns what the caller says into text. The model or agent reads it and writes an answer. Text to speech turns the answer into audio and plays it back. Each of the three pieces can be swapped on its own.
Intermediate Speech recognition keeps mishearing two drug names. What do you try?
Model answer
A phrase list with those two names. It needs no data and no training, and it boosts those words. If it's hundreds of terms or the audio is noisy, I'd train custom speech on related text or labelled audio.
Experienced developer When do you move from the Speech SDK loop to Voice Live?
Model answer
When latency and natural turn-taking matter, like a phone line. Voice Live handles speech in, the model or agent and speech out over one connection, with noise suppression, echo cancellation and end-of-turn detection, so I'm not stitching three calls together and handling interruptions myself.
Scenario Callers say the agent sounds rushed when it reads times and codes. What do you change?
Model answer
I'd send the reply as SSML instead of plain text: a break before the time, a slightly slower prosody rate for it, and say-as for codes. The words don't change, only the delivery.
Quick revision
Key points
- One voice turn is speech to text, model or agent, text to speech.
- Phrase list is the quick, no-training fix. Custom speech is for many terms, accents or noise.
- A custom speech model is used by setting its endpoint ID in the SpeechConfig.
- SSML controls pauses, rate, pitch and style of the spoken reply.
- Voice Live is the low-latency speech to speech option for live agents.
Important terminology
- Speech to text
- Azure Speech converting spoken audio into text, in real time or in batch.
- Text to speech
- Azure Speech turning text into spoken audio with a neural voice.
- SSML
- Speech Synthesis Markup Language. XML that sets the voice, pauses, rate, pitch and style of synthesized speech.
- Phrase list
- A short list of words and phrases that biases recognition toward them. No training required.
- Custom speech
- A speech recognition model trained on your text or labelled audio and called through a custom endpoint ID.
- Voice Live
- A real-time speech to speech interface for models and agents, with noise suppression, echo cancellation and end-of-turn detection.
Common mistakes
- Training custom speech for two misheard words.
- Using SSML and expecting it to fix recognition errors. It only shapes output.
- Stitching three slow calls together for a live phone line.
Exam tips
- "A few words misheard, no training" = phrase list.
- "Industry vocabulary, accents, noise" = custom speech.
- "Add a pause and slow the rate" = SSML.
Five quick revision questions
-
1.What does SSML change?Show
How synthesized speech is delivered (pauses, rate, pitch, style).
-
2.What do you set to use a custom speech model?Show
Its endpoint ID.
-
3.What does Voice Live combine?Show
Speech in, the model or agent, and speech out on one connection.
-
4.Which fix needs no training for a few words?Show
A phrase list.
-
5.What turns the agent reply into spoken audio?Show
Text to speech with a neural voice.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Speech Translation and Reasoning over Audio
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.