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 = "qwen-audio-3.1-asr-flash-message",
Url = "wss://WorkspaceId.ap-southeast-1.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();