Learn about real-time speech synthesis features, streaming calls, and ways to improve synthesis quality.
Features
Real-time speech synthesis accepts text segments and streams audio back, enabling speech output as a large language model generates text.
- Languages and dialects: Select a model and voice for the target language, or use an instruction to specify a dialect. See Dialects.
- Expressive speech: Adjust delivery with natural-language instructions, or insert emotion and nonverbal tags into the text. See Instruction control and Emotion and nonverbal tags.
- Custom voices: Create a voice from an audio sample with voice cloning, or from a text description with voice design.
- Fine-grained control and formulas: Use SSML and LaTeX to control pauses and pronunciation, or convert formulas to speech.
- Markdown filtering: Convert Markdown content such as tables into text suitable for reading aloud. See Markdown filtering.
- Audio controls: Adjust speed, pitch, volume, and bitrate, and output common audio formats such as PCM, WAV, MP3, and Opus at sample rates up to 48 kHz. See the corresponding API parameters for supported values and conditions.
Supported features vary by model and voice. Check the scope in the corresponding feature documentation.To submit complete text in one HTTP request, see Non-real-time speech synthesis.
Get started
Install the DashScope SDK, then get an API key in the console and set the DASHSCOPE_API_KEY environment variable.
- Qwen-Audio-TTS (recommended)
- CosyVoice
This example uses qwen-audio-3.1-tts-flash and the
longanhuan_v3.1 system voice in Beijing. It sends text in segments and saves the streamed audio to output.mp3.Java
Improve synthesis quality
Languages and pronunciation
Choose an approach based on what you need to control:
| Requirement | Approach |
|---|---|
| Set the target language of synthesized speech | Use language_hints to specify the overall synthesis language, guide the pronunciation of numbers, abbreviations, and symbols, and improve synthesis in less widely used languages. |
| Correct specific words or replace text | With Qwen-Audio-TTS, use hot_fix to specify a word’s pronunciation in pinyin or replace the word before synthesis. |
| Control pauses, number reading, or pronunciation precisely | Mark the relevant text with SSML tags to control pauses, reading rules, and pronunciation. |
| Read mathematical formulas | Use the CosyVoice LaTeX feature to convert supported mathematical formulas into Chinese speech. |
When using SSML, submit the complete SSML text in a single input and receive audio incrementally. Fragmented text input is not supported.
Markdown filtering
When synthesizing content with Markdown tables or links, set enable_markdown_filter to true to convert Markdown into text suitable for reading aloud. Qwen-Audio-TTS and CosyVoice support this feature, except for cosyvoice-v2. For configuration details, see the Qwen-Audio-TTS API and CosyVoice API.
Instruction control
Use instruction to specify the synthesis language and describe the speech rate, emotion, or speaking style in natural language to control the synthesized speech.
To create a new voice with a specific gender, age, or vocal character, or for guidance and examples on writing voice descriptions, see voice design.
- Qwen-Audio-TTS
- CosyVoice
System, cloned, and designed voices for qwen-audio-3.1-tts-plus, qwen-audio-3.1-tts-flash, qwen-audio-3.0-tts-plus, and qwen-audio-3.0-tts-flash all support natural-language instructions through
instruction in synthesis requests.We recommend specifying the synthesis language and desired effect in instruction to improve synthesis quality. The language specified in the instruction must match the language of the text to be synthesized. For example, when synthesizing Dutch text, set:Dialects
Use dialect synthesis to generate speech in Chinese dialects such as Henan or Sichuan dialect. How you select a dialect depends on the model and voice type.
- Qwen-Audio-TTS
- CosyVoice
-
System voices: Select a voice from the Qwen-Audio-TTS voice list that supports the dialect. A voice that directly supports the dialect requires no additional setting. For voices that support dialect instructions, use the instruction control parameter
instruction.For the multilingual and dialect voices of qwen-audio-3.1-tts-flash, you can also uselanguage_hintsto specify a dialect. See the multilingual and dialect voice settings. -
Cloned voices: Specify a dialect with the instruction control parameter
instruction.
instruction="请讲上海话。" when initializing SpeechSynthesizer to synthesize Chinese text in Shanghainese.Emotion and nonverbal tags
Applies to qwen-audio-3.1-tts-plus, qwen-audio-3.1-tts-flash, qwen-audio-3.0-tts-plus, and qwen-audio-3.0-tts-flash.
text, without additional parameters.
Usage examples
This text starts with an excited delivery, inserts laughter, and then continues speaking:
Supported tags
- Control tags
- Nonverbal tags
A control tag sets the emotion or style of the following text until the next control tag. When long sentences are automatically segmented, the effect is bounded by the resulting text segment.
| Tag | Description |
|---|---|
[sad] | Sad |
[amazed] | Amazed |
[deep and loud shouting] | Deep, loud shouting |
[trembling] | Trembling |
[angry] | Angry |
[excited] | Excited |
[sarcastic] | Sarcastic |
[curious] | Curious |
[like dracula] | Dracula-like delivery |
[bored] | Bored |
[tired] | Tired |
[scornful] | Scornful |
[shouting] | Shouting |
[asmr] | Soft ASMR delivery |
[panicked] | Panicked |
[mischievously] | Mischievous |
[empathetic] | Empathetic |
[whispers] | Whispering |
[reluctantly] | Reluctant |
[crying] | Crying |
[serious] | Serious |
[very slowly] | Very slow |
[very fast] | Very fast |
Apply in production
For text submission, audio playback, connection reuse, concurrency management, and performance troubleshooting, see Speech synthesis best practices. Keep request frequency and concurrency within the model’s rate limits.
Cancel task
With Qwen-Audio-TTS or CosyVoice, send a cancellation instruction to interrupt the current synthesis task. The server ends the task and returns task-finished.
| Method | Version requirement | Usage |
|---|---|---|
| Python SDK | 2.0.1 or later | Call session.cancel() on the session object (the session returned by client.audio.tts.connect). |
| Java SDK | 2.22.26 or later | Call SpeechSynthesizer.streamingCancel(). |
| Raw WebSocket protocol | No SDK required | Send finish-task with directive=cancel in input. |
Supported models
- China (Beijing)
- Singapore
- Qwen-Audio-TTS: qwen-audio-3.1-tts-plus, qwen-audio-3.1-tts-flash, qwen-audio-3.0-tts-plus, qwen-audio-3.0-tts-flash
- CosyVoice: cosyvoice-v3.5-plus, cosyvoice-v3.5-flash, cosyvoice-v3-plus, cosyvoice-v3-flash, cosyvoice-v2
- Qwen3-TTS: qwen3-tts-flash-realtime
- Sambert: sambert-zhinan-v1, sambert-zhiqi-v1, sambert-zhichu-v1, sambert-zhide-v1, sambert-zhijia-v1, sambert-zhiru-v1, sambert-zhiqian-v1, sambert-zhixiang-v1, sambert-zhiwei-v1, sambert-zhihao-v1, sambert-zhijing-v1, sambert-zhiming-v1, sambert-zhimo-v1, sambert-zhina-v1, sambert-zhishu-v1, sambert-zhistella-v1, sambert-zhiting-v1, sambert-zhixiao-v1, sambert-zhiya-v1, sambert-zhiye-v1, sambert-zhiying-v1, sambert-zhiyuan-v1, sambert-zhiyue-v1, sambert-zhigui-v1, sambert-zhishuo-v1, sambert-zhimiao-emo-v1, sambert-zhimao-v1, sambert-zhilun-v1, sambert-zhifei-v1, sambert-zhida-v1, sambert-camila-v1, sambert-perla-v1, sambert-indah-v1, sambert-clara-v1, sambert-hanna-v1, sambert-beth-v1, sambert-betty-v1, sambert-cally-v1, sambert-cindy-v1, sambert-eva-v1, sambert-donna-v1, sambert-brian-v1, sambert-waan-v1. For details, see Sambert voice list
API reference
Mobile applications that require low latency and stable audio transmission on weak networks can use AOQ. For AOQ access, protocol differences, and model support across AOQ, WebRTC, and WebSocket, see Realtime API overview.
FAQ
How do I troubleshoot silent audio when using a cloned voice?
How do I troubleshoot silent audio when using a cloned voice?
Check that
voice is the ID of a successfully created voice and that its target_model matches the synthesis model. For voice status, source audio requirements, and quality guidance, see Voice cloning.How do I restrict an API key to only the speech synthesis service (permission isolation)?
How do I restrict an API key to only the speech synthesis service (permission isolation)?
Create a new workspace and grant access to specific models only. This limits the scope of the API key. For details, see Manage workspaces.
Can an API key from a sub-workspace call Qwen-Audio-TTS/CosyVoice models?
Can an API key from a sub-workspace call Qwen-Audio-TTS/CosyVoice models?
In the default workspace, all models are accessible.In a sub-workspace, you need to authorize models for the sub-workspace associated with the API key. For details, see Model calls in a sub-workspace.