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.
Synthesize two text segments with the longanyang voice and write the audio chunks to output.wav in order. Play the file when the program finishes.
using DashScope.Speech;
await using var client = new CosyVoiceSpeechSynthesizer(new CosyVoiceSynthesizerOptions
{
Model = "cosyvoice-v3-plus",
Voice = "longanyang",
Url = "wss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/inference",
Format = "wav",
SampleRate = 16000,
});
using var output = File.Create("output.wav");
await foreach (var chunk in client.StreamAudioAsync(["Good afternoon. ", "Welcome to our meeting."]))
{
await output.WriteAsync(chunk);
}