Prompt
How do I generate speech with SSML tags in an API?
Latest observation
Nov 12, 2026
OpenAI APIWeb search: off
To generate speech with SSML in a text-to-speech API, you typically:
- Wrap your spoken text in SSML
- Send it to the TTS endpoint with the correct content type / input type
- Choose a voice and output format
- Read back the audio response
What SSML is
SSML (Speech Synthesis Markup Language) lets you control pronunciation, pauses, emphasis, speaking rate, pitch, etc.
Example:
<speak>
Hello there.
<break time="500ms"/>
<emphasis level="strong">Welcome</emphasis> to our service.
</speak>
Typical API flow
Most TTS APIs expect:
- plain text or SSML
- a voice name
- an audio output format like MP3 or WAV
Example request body
{
"input": {
"ssml": "<speak>Hello <break time='300ms'/> world.</speak>"
},
"voice": {
"languageCode": "en-US",
"name": "en-US-Neural2-J"
},
"audioConfig": {
"audioEncoding": "MP3"
}
}
cURL example
curl -X POST "https://api.example.com/tts" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"input": {
"ssml": "<speak>Hello <break time=\"300ms\"/> world.</speak>"
},
"voice": {
"languageCode": "en-US",
"name": "en-US-Neural2-J"
},
"audioConfig": {
"audioEncoding": "MP3"
}
}'
Important SSML rules
- Your SSML must usually be wrapped in
<speak>...</speak> - Escape quotes properly in JSON
- Not all SSML tags are supported by every provider
- Some APIs require SSML to be sent in a dedicated field like
ssml, while others use a generictextfield plus a flag liketextType: "ssml"
Common SSML tags
<break time="500ms"/>— pause<emphasis>— stress words<prosody rate="slow" pitch="+2st">— control speech rate/pitch<say-as interpret-as="characters">API</say-as>— spell out text<sub alias="World Wide Web Consortium">W3C</sub>— alternate pronunciation
Example:
<speak>
Please call <say-as interpret-as="characters">AI</say-as>.
<break time="250ms"/>
This is <prosody rate="slow">slower speech</prosody>.
</speak>
If you’re using a specific provider
The exact request format depends on the API:
- Google Cloud Text-to-Speech
- Amazon Polly
- Azure Speech
- OpenAI-compatible TTS
- others
If you tell me which API/provider you’re using and your language (Python, Node.js, cURL, etc.), I can give you the exact working example.