Skip to main content

CosyVoice C# SDK

快速开始

按SDK简介安装 SDK 并配置 API Key。将示例地址中的 WorkspaceId 替换为同地域的业务空间 ID。 用 longanyang 音色分段合成两句话,将收到的音频依次写入 output.wav。运行后即可播放该文件。
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(["今天下午三点开会。", "请提前入场。"]))
{
    await output.WriteAsync(chunk);
}

详细参考