Fun-ASR-Realtime C# SDK overview

Updated at:

Stream audio to Fun-ASR-Realtime with the C# SDK and receive recognition results.

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.

Save the sample audio as asr_example.wav. The example reads the file in chunks to simulate live input without a microphone.

Transcribe the audio and print the final text of each sentence to the console.

using DashScope.Speech;

await using var client = new FunAsrSpeechTranscriber(new FunAsrTranscriberOptions
{
    Model = "fun-asr-realtime",
    Url = "wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference",
    Format = "wav",
    SampleRate = 16000,
});
client.SentenceEnd += (_, e) => Console.WriteLine(e.Sentence.Text);

using var audio = File.OpenRead("asr_example.wav");
byte[] buffer = new byte[3200];
await client.StartAsync();
int count;
while ((count = await audio.ReadAsync(buffer)) > 0)
{
    await client.SendAudioAsync(buffer.AsMemory(0, count));
    await Task.Delay(100);
}
await client.StopAsync();

Call workflow

  1. Create a FunAsrSpeechTranscriber instance and subscribe to events (such as SentenceEnd; subscribe to PartialResult as well if you want interim results).
  2. Call StartAsync to connect, send run-task, and wait for task-started.
  3. After TranscriberStarted, call SendAudioAsync continuously at the audio playback rate.
  4. Receive interim and final results in SentenceBegin, PartialResult, and SentenceEnd (interim PartialResult text may change; use SentenceEnd for the final text).
  5. After all audio is sent, call StopAsync and wait for task-finished (Completed).
  6. Call DisposeAsync to release the connection when done.

Request parameters

Pass FunAsrTranscriberOptions to the FunAsrSpeechTranscriber constructor. Optional values set to null are omitted from the request.

ParameterTypeDefaultDescription

Model

string

qwen-audio-3.1-asr-flash-streaming

Model ID. Set the model for this family explicitly.

Format

string

pcm

Audio format.

SampleRate

int

16000

Set the sample rate in Hz to match the input audio. fun-asr-realtime supports any sample rate; fun-asr-flash-8k-realtime supports only 8000 Hz.

MaxSentenceSilence

int?

null

VAD end-of-sentence silence threshold in milliseconds.

MultiThresholdModeEnabled

bool?

null

Enable multi-threshold VAD segmentation.

Heartbeat

bool?

null

Keep the connection alive while sending silent audio.

VocabularyId

string?

null

Precompiled vocabulary ID.

LanguageHints

IList<string>?

null

Language hints, such as ["zh"]. Only the first value takes effect.

SpeechNoiseThreshold

float?

null

Speech/noise threshold.

SpecialWordFilter

string?

null

Sensitive-word filtering rules as a JSON string.

ExtraParametersJson

string?

null

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