Sambert C# SDK overview

Updated at:

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

  1. Create a SambertSpeechSynthesizer instance (specify the speaker via Model; Sambert does not use a separate Voice option) and subscribe to events such as SentenceTimestamps as needed.
  2. Call SynthesizeAsync with the complete text to get all audio bytes in one call.
  3. To play audio as it arrives, use StreamAudioAsync instead and process audio chunks in order.
  4. To receive word-level timestamps, enable WordTimestampEnabled. For phoneme-level timestamps, also enable PhonemeTimestampEnabled. Handle SentenceTimestamps to receive the timestamps.
  5. The server triggers SynthesisCompleted when all audio is delivered; call DisposeAsync when 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.

ParameterTypeDefaultDescription

Model

string

sambert-zhichu-v1

Model ID. Set the model for this family explicitly.

Format

string

wav

Audio format.

SampleRate

int

16000

Audio sample rate in Hz.

Volume

int?

null

Volume, from 0 to 100.

Rate

double?

null

Speech rate multiplier.

Pitch

double?

null

Pitch multiplier.

WordTimestampEnabled

bool?

null

Return word-level timestamps.

PhonemeTimestampEnabled

bool?

null

Return phoneme timestamps; requires WordTimestampEnabled=true.

ExtraParametersJson

string?

null

Pass a JSON object as a string. Its fields are merged into the protocol parameters object.