Sambert C# SDK overview
Use the C# SDK to synthesize speech with Sambert 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.
Sambert is available only in Beijing. Synthesize a sentence with sambert-brian-v1 and save the audio to output.wav.
using DashScope.Speech;
await using var client = new SambertSpeechSynthesizer(new SambertSynthesizerOptions
{
Model = "sambert-brian-v1",
Url = "wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference",
Format = "wav",
SampleRate = 16000,
});
var audio = await client.SynthesizeAsync("Good afternoon. Welcome to our meeting.");
await File.WriteAllBytesAsync("output.wav", audio);
Call workflow
- Create a
SambertSpeechSynthesizerinstance (specify the speaker viaModel; Sambert does not use a separateVoiceoption) and subscribe to events such asSentenceTimestampsas needed. - Call
SynthesizeAsyncwith the complete text to get all audio bytes in one call. - To play audio as it arrives, use
StreamAudioAsyncinstead and process audio chunks in order. - To receive word-level timestamps, enable
WordTimestampEnabled. For phoneme-level timestamps, also enablePhonemeTimestampEnabled. HandleSentenceTimestampsto receive the timestamps. - The server triggers
SynthesisCompletedwhen all audio is delivered; callDisposeAsyncwhen done.
Request parameters
Pass SambertSynthesizerOptions to the SambertSpeechSynthesizer constructor. When WordTimestampEnabled, and PhonemeTimestampEnabled are null, the SDK still sends them as false. Sambert takes the full text once per instance. Select the speaker with Model, not Voice.
| Parameter | Type | Default | Description |
|---|---|---|---|
|
|
| Model ID. Set the model for this family explicitly. |
|
|
| Audio format. |
|
|
| Audio sample rate in Hz. |
|
|
| Volume, from 0 to 100. |
|
|
| Speech rate multiplier. |
|
|
| Pitch multiplier. |
|
|
| Return word-level timestamps. |
|
|
| Return phoneme timestamps; requires |
|
|
| Pass a JSON object as a string. Its fields are merged into the protocol |