Use the C# SDK to synthesize speech with Qwen-Audio-TTS / CosyVoice and receive audio chunks.
Quick start
Follow SDK overview to install the SDK and configure your API key. Replace WorkspaceId in the example endpoint with your workspace ID from the same region.
- Qwen-Audio-TTS
- CosyVoice
Synthesize two text segments with the
longanfengyue_v3.1 voice and write the audio chunks to output.wav in order. Play the file when the program finishes.Call workflow
- Create a
CosyVoiceSpeechSynthesizerinstance with a voice and output format matching the model, and subscribe to events such asAudioReceivedandSentenceProgressas needed. - When using
SendTextAsync, callStartAsyncto connect and sendrun-task. - Call
SendTextAsyncto send text segments; if you already have all segments, you can callStreamAudioAsyncorSynthesizeAsyncdirectly without callingStartAsyncfirst. - Receive audio chunks in
AudioReceivedand sentence progress or timestamps inSentenceProgress(or read chunks in order fromStreamAudioAsync). - When using
SendTextAsync, callStopAsyncafter sending all text and wait fortask-finished(SynthesisCompleted). - To interrupt the current synthesis task while keeping the connection open, call
CancelSynthesisKeepConnectionAsync; callDisposeAsyncwhen done.
Request parameters
Pass CosyVoiceSynthesizerOptions to the CosyVoiceSpeechSynthesizer constructor. When EnableSsml, WordTimestampEnabled, EnableAigcTag, and EnableMarkdownFilter are null, the SDK still sends them as false.
| Parameter | Type | Default | Description |
|---|---|---|---|
Model | string | qwen-audio-3.1-tts-flash | Model ID. Set the model for this family explicitly. |
Voice | string | longanfengyue_v3.1 | Voice ID matched to the selected model. Qwen-Audio-TTS: Supported voices; CosyVoice: Supported voices. |
Format | string | pcm | Audio format. |
SampleRate | int | 22050 | Audio sample rate in Hz. |
Volume | int? | null | Volume, from 0 to 100. |
Rate | double? | null | Speech rate multiplier. |
Pitch | double? | null | Pitch multiplier. |
BitRate | int? | null | Output bitrate in kbps (6 to 510). Effective only when Format is opus or mp3. |
Seed | int? | null | Random seed. |
EnableSsml | bool? | null | Enable SSML parsing for complete SSML input. Send the complete SSML text in a single continue-task. With SynthesizeAsync, pass only one text segment. Audio can still be received as a stream. |
WordTimestampEnabled | bool? | null | Return word-level timestamps. |
LanguageHints | IList<string>? | null | For multilingual or dialect voices on qwen-audio-3.1-tts-flash, see Qwen-Audio-TTS. For CosyVoice, pass one target language; only the first value is used. See CosyVoice · Client events. |
Instruction | string? | null | Voice instruction. |
EnableAigcTag | bool? | null | Embed AIGC metadata in wav, mp3, or opus audio.Among CosyVoice models, only cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2 support this option. |
AigcPropagator | string? | null | AIGC content propagator identifier. Sent only when EnableAigcTag is true; in the CosyVoice series, supported only by cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2. |
AigcPropagateId | string? | null | Identifier of the AIGC content distribution event. Sent only when EnableAigcTag is true. Among CosyVoice models, only cosyvoice-v3-flash, cosyvoice-v3-plus, and cosyvoice-v2 support this option. |
HotFixJson | string? | null | JSON object with pronunciation and replace rules. cosyvoice-v2 does not support this parameter. |
ExtraParametersJson | string? | null | Pass a JSON object as a string. Its fields are merged into the protocol parameters object. |
EnableMarkdownFilter | bool? | null | Filter Markdown markers in input. cosyvoice-v2 does not support this parameter. |