C# SDK Methods and events
Client class reference for the Bailian.DashScope SDK, covering methods, events, properties, and result objects for speech recognition, speech synthesis, real-time voice conversation, and real-time translation.
FunAsrSpeechTranscriber
Methods
ct (CancellationToken, optional): cancels the current asynchronous call.
| Method | Returns | Description |
|---|---|---|
|
| Connect and wait for |
|
| Send an audio frame after startup. |
|
| Send |
|
| Immediately close the connection. Repeated calls are allowed. |
|
| Read a PCM stream, send frames, and return final sentences. Frames default to 20 ms. |
|
| Release client resources. |
|
| Qwen-Audio-ASR-Message: Send the protocol context array. |
Events
| Event | Type | Description |
|---|---|---|
|
| Task started. |
|
| Sentence start. |
|
| Intermediate recognition result. |
|
| Final recognition result for a sentence. |
|
| Task finished. |
|
| Task failure or unexpected disconnection. |
Results
Read usage in RawPayload for the usage fields returned by the model. The compatibility duration field may be absent from completion events.
| Property | Type | Description |
|---|---|---|
|
| Identifier. |
RecognitionSentenceEventArgs
| Property | Type | Description |
|---|---|---|
|
| Sentence details. |
|
| Original response JSON. |
RecognitionSentence
| Property | Type | Description |
|---|---|---|
|
| Identifier. |
|
| Start time in milliseconds. |
|
| End time in milliseconds; may be absent before finalization. |
|
| Text. |
|
| Whether this is a sentence start. |
|
| Whether this is the final result for a sentence. |
|
| Audio channel index; channel numbering starts at 0. |
|
| Speaker identifier. |
|
| Word details. |
|
| Stashed recognition text. |
|
| Identifier. |
RecognitionWord
| Property | Type | Description |
|---|---|---|
|
| Start time in milliseconds. |
|
| End time in milliseconds; may be absent before finalization. |
|
| Text. |
|
| Punctuation. |
|
| Whether the word is finalized. |
|
| Speaker identifier. |
TranscriptionCompletedEventArgs
| Property | Type | Description |
|---|---|---|
|
| Audio duration in seconds ( |
|
| Original response JSON. |
CosyVoiceSpeechSynthesizer
Methods
ct (CancellationToken, optional): cancels the current asynchronous call.
| Method | Returns | Description |
|---|---|---|
|
| Connect and wait for |
|
| Append a text segment after startup. |
|
| Send |
|
| Cancel synthesis with |
|
| Immediately close the connection. Repeated calls are allowed. |
|
| Send text segments and yield audio chunks. |
|
| Collect all audio from |
|
| Release client resources. |
Events
| Event | Type | Description |
|---|---|---|
|
| Task started. |
|
| Audio bytes in order; append chunks to form the output file. |
|
| Sentence synthesis progress: begin, synthesis, and end. |
|
| Task finished. |
|
| Task failure or unexpected disconnection. |
Results
| Property | Type | Description |
|---|---|---|
|
| Identifier. |
|
| Qwen-Audio-TTS: Final task usage. After CosyVoice: Final task usage. After |
SynthesisSentenceEventArgs
| Property | Type | Description |
|---|---|---|
|
|
|
|
| Identifier. |
|
| Original input text. |
|
| Normalized synthesis text. |
|
|
|
|
| Word details. |
SambertSpeechSynthesizer
Methods
ct (CancellationToken, optional): cancels the current asynchronous call.
| Method | Returns | Description |
|---|---|---|
|
| Send the complete text and wait for |
|
| Wait for server-driven completion; Sambert does not use |
|
| Immediately close the connection. Repeated calls are allowed. |
|
| Submit the complete text and yield audio chunks until completion. |
|
| Submit the complete text and return all audio as a byte array. |
|
| Release client resources. |
Events
| Event | Type | Description |
|---|---|---|
|
| Task started. |
|
| Audio bytes in order; append chunks to form the output file. |
|
| Word and phoneme timestamps when enabled. |
|
| Task finished. |
|
| Task failure or unexpected disconnection. |
Results
| Property | Type | Description |
|---|---|---|
|
| Identifier. |
|
| Final task usage. After |
SambertSentenceEventArgs
| Property | Type | Description |
|---|---|---|
|
| Start time in milliseconds. |
|
| End time in milliseconds; may be absent before finalization. |
|
| Word details. With |
|
|
|
FunAsrFileTranscriber
In the DashScope.Transcription namespace, used for asynchronous submission, polling, and result download of recorded audio transcription (Qwen-Audio-ASR-Flash-Filetrans, Fun-ASR, and Paraformer).
Methods
ct (CancellationToken, optional): cancels the current asynchronous call.
| Method | Returns | Description |
|---|---|---|
|
| Submits an asynchronous transcription task and returns |
|
| Queries the current status and subtask list of a task once. |
|
| Polls until the task reaches a terminal state ( |
|
| Downloads and parses the transcription result JSON file from a subtask |
|
| Submits, polls, and downloads all succeeded subtask results in one call; throws if the overall task fails or all subtasks fail. |
|
| Cancels a queued task (only supported while |
|
| Releases the underlying HTTP client resources. |
Result objects
FileTranscriptionSubmission
| Property | Type | Description |
|---|---|---|
RequestId | string | Request ID. |
TaskId | string | Asynchronous task ID (valid for 24 hours). |
TaskStatus | FunAsrTaskStatus | Current task status. |
Raw | JsonObject? | Raw submission response JSON. |
FileTranscriptionResult
| Property | Type | Description |
|---|---|---|
RequestId | string? | Request ID. |
TaskId | string | Asynchronous task ID. |
TaskStatus | FunAsrTaskStatus | Task status. |
IsTerminal | bool | Whether the task has reached a terminal state (Succeeded, Failed, or Canceled). |
Code | string? | Error code when the overall task fails. |
Message | string? | Error message when the overall task fails. |
SubmitTime | string? | Task submission timestamp. |
ScheduledTime | string? | Task scheduling timestamp. |
EndTime | string? | Task completion timestamp. |
UsageDurationSeconds | long? | Billed audio duration in seconds. |
Results | IReadOnlyList<FileTranscriptionSubtask> | Subtask results; check each subtask's SubtaskStatus even when the overall task is Succeeded. |
Raw | JsonObject? | Raw query response JSON. |
FileTranscriptionSubtask
| Property | Type | Description |
|---|---|---|
FileUrl | string | Source audio URL. |
SubtaskStatus | FunAsrTaskStatus | Subtask status. |
TranscriptionUrl | string? | Temporary download URL for the transcription result JSON (valid for 24 hours). |
Code | string? | Subtask error code when failed. |
Message | string? | Subtask error message when failed. |
FileTranscriptionOutput
| Property | Type | Description |
|---|---|---|
Subtask | FileTranscriptionSubtask | Subtask metadata. |
Transcription | TranscriptionFile | Downloaded and parsed transcription result file. |
TranscriptionFile
| Property | Type | Description |
|---|---|---|
FileUrl | string | Source audio URL. |
Properties | TranscriptionAudioProperties? | Source audio properties. |
Transcripts | IReadOnlyList<TranscriptChannel> | Per-channel transcription results. |
Raw | JsonObject? | Raw result file JSON. |
TranscriptionAudioProperties
| Property | Type | Description |
|---|---|---|
AudioFormat | string? | Audio encoding format (such as pcm_s16le). |
Channels | IReadOnlyList<int> | Channel index list. |
OriginalSamplingRate | int? | Original sample rate in Hz. |
OriginalDurationMs | long? | Original audio duration in milliseconds. |
TranscriptChannel
| Property | Type | Description |
|---|---|---|
ChannelId | int | Audio channel index. |
ContentDurationMs | long | Speech content duration in milliseconds. |
Text | string | Full concatenated transcript for the channel. |
Sentences | IReadOnlyList<TranscriptSentence> | Sentence-level results. |
TranscriptSentence
| Property | Type | Description |
|---|---|---|
SentenceId | int | Sentence sequence number. |
BeginTimeMs | long | Start time in milliseconds. |
EndTimeMs | long | End time in milliseconds. |
Text | string | Sentence text. |
SpeakerId | int? | Speaker index (returned when speaker diarization is enabled). |
Words | IReadOnlyList<TranscriptWord> | Word-level timestamps. |
TranscriptWord
| Property | Type | Description |
|---|---|---|
BeginTimeMs | long | Word start time in milliseconds. |
EndTimeMs | long | Word end time in milliseconds. |
Text | string | Word text. |
Punctuation | string | Trailing punctuation. |
FunAsrFlashFileTranscriber
In the DashScope.Transcription namespace, used for synchronous or SSE streaming recorded audio transcription (Qwen-Audio-ASR-Flash and Fun-ASR-Flash).
Methods
ct (CancellationToken, optional): cancels the current asynchronous call.
| Method | Returns | Description |
|---|---|---|
|
| Performs a single synchronous transcription request and returns the final result. |
|
| Streams interim and final sentence results frame by frame via SSE. |
|
| Releases the underlying HTTP client resources. |
Result objects
FlashTranscriptionResult
| Property | Type | Description |
|---|---|---|
RequestId | string | Request ID. |
Text | string | Full recognized text. |
Sentence | FlashSentence | Current sentence result (updated per frame in streaming mode). |
UsageDurationSeconds | long? | Processed audio duration in seconds. |
Raw | JsonObject? | Raw response JSON. |
FlashSentence
| Property | Type | Description |
|---|---|---|
SentenceId | int | Sentence sequence number. |
SentenceEnd | bool | Whether this is the final result for the sentence. |
BeginTimeMs | long | Sentence start time in milliseconds. |
EndTimeMs | long? | Sentence end time in milliseconds (returned only when SentenceEnd is true). |
Text | string | Sentence text. |
ChannelId | int | Channel index. |
Words | IReadOnlyList<FlashWord> | Word-level timestamps. |
FlashWord
| Property | Type | Description |
|---|---|---|
BeginTimeMs | long | Word start time in milliseconds. |
EndTimeMs | long? | Word end time in milliseconds. |
Text | string | Word text. |
Punctuation | string | Trailing punctuation. |
Fixed | bool? | When false, timestamps may still be adjusted in subsequent interim frames. |
QwenRealtimeConversation
In the DashScope.Qwen namespace, used for real-time voice conversation with Qwen-Audio-Realtime and Qwen-Omni-Realtime.
Methods
ct (CancellationToken, optional): cancels the current asynchronous call.
| Method | Returns | Description |
|---|---|---|
ConnectAsync(CancellationToken ct = default) | Task | Connects, waits for session.created, and sends session.update. |
AppendAudioAsync(ReadOnlyMemory<byte> pcm, CancellationToken ct = default) | Task | Sends a PCM audio frame (Base64-encoded internally as input_audio_buffer.append). |
CommitAudioAsync(CancellationToken ct = default) | Task | Commits the audio buffer with input_audio_buffer.commit in PushToTalk mode. |
CreateResponseAsync(JsonObject? responseOptions = null, CancellationToken ct = default) | Task | Sends response.create to request a response; responseOptions overrides per-turn settings. |
SendItemAsync(JsonObject item, CancellationToken ct = default) | Task | Adds an item to the conversation using conversation.item.create. |
SendFunctionCallOutputAsync(string callId, string outputJson, CancellationToken ct = default) | Task | Returns tool execution output using the original callId and JSON result. |
SendRawEventAsync(string frameJson, CancellationToken ct = default) | Task | Sends a raw client event JSON frame. |
FinishAsync(CancellationToken ct = default) | Task | Gracefully ends the session according to FinishMode. |
AbortAsync() | Task | Immediately closes the connection and discards in-flight results. |
DisposeAsync() | ValueTask | Asynchronously releases client resources. |
Events
| Event | Type | Trigger |
|---|---|---|
SessionReady | EventHandler<string?> | Session is ready; argument is session.id. |
UserSpeechStarted | EventHandler<QwenSpeechEventArgs> | Server VAD detected start of user speech. |
UserSpeechStopped | EventHandler<QwenSpeechEventArgs> | Server VAD detected end of user speech. |
UserTranscriptUpdated | EventHandler<QwenTranscriptEventArgs> | Interim transcript of user speech. |
UserTranscriptCompleted | EventHandler<QwenTranscriptEventArgs> | Final transcript of a user speech utterance. |
AssistantTextDelta | EventHandler<QwenTextDeltaEventArgs> | Incremental assistant response text. |
AssistantTextCompleted | EventHandler<QwenTranscriptEventArgs> | Complete assistant response text. |
AssistantAudioChunk | EventHandler<QwenAudioChunkEventArgs> | Assistant audio chunk (24 kHz mono 16-bit little-endian raw PCM). |
AssistantAudioCompleted | EventHandler | All assistant audio for the current turn has been delivered. |
FunctionCallReceived | EventHandler<QwenFunctionCallEventArgs> | Model requests a tool call. |
ResponseCompleted | EventHandler<QwenResponseSummary> | Received response.done with status and usage. |
RawServerEvent | EventHandler<QwenServerEventArgs> | Raw server event. |
ErrorOccurred | EventHandler<DashScopeErrorEventArgs> | Server error or connection failure. |
Properties
| Property | Type | Description |
|---|---|---|
SessionId | string? | Server session ID. |
FinishMode | QwenRealtimeFinishMode | Actual finish mode used for the session. |
Result objects
QwenResponseSummary
| Property | Type | Description |
|---|---|---|
Status | string? | Response status (completed, failed, or incomplete). |
FailureReason | string? | Failure reason. |
TotalTokens | int? | Total tokens (per turn for conversation; session cumulative for translation). |
InputTokens | int? | Input tokens. |
OutputTokens | int? | Output tokens. |
AudioInputTokens | int? | Audio input tokens. |
AudioOutputTokens | int? | Audio output tokens. |
QwenSpeechEventArgs
| Property | Type | Description |
|---|---|---|
AudioMs | long | Speech start or stop offset in milliseconds. |
ItemId | string? | Item ID. |
QwenTranscriptEventArgs
| Property | Type | Description |
|---|---|---|
Text | string | Current or final transcript text. |
ItemId | string? | Item ID. |
QwenTextDeltaEventArgs
| Property | Type | Description |
|---|---|---|
Delta | string | Incremental text chunk. |
ItemId | string? | Item ID. |
QwenAudioChunkEventArgs
| Property | Type | Description |
|---|---|---|
Pcm | byte[] | Audio chunk bytes. |
QwenFunctionCallEventArgs
| Property | Type | Description |
|---|---|---|
CallId | string | Tool call ID; pass the original value when returning output. |
Name | string? | Tool name. |
ArgumentsJson | string? | Tool arguments JSON string. |
QwenServerEventArgs
| Property | Type | Description |
|---|---|---|
Type | string? | Server event type. |
Root | JsonObject | Full event JSON object. |
QwenLiveTranslator
In the DashScope.Qwen namespace, used for real-time speech and audio-video translation with Qwen-LiveTranslate-Realtime.
Methods
ct (CancellationToken, optional): cancels the current asynchronous call.
| Method | Returns | Description |
|---|---|---|
ConnectAsync(CancellationToken ct = default) | Task | Connects, waits for session.created, and sends session.update. |
AppendAudioAsync(ReadOnlyMemory<byte> pcm, CancellationToken ct = default) | Task | Sends a PCM audio frame (Base64-encoded internally as input_audio_buffer.append). |
AppendImageAsync(string imageBase64, CancellationToken ct = default) | Task | Sends a Base64-encoded image frame as input_image_buffer.append. |
SendRawEventAsync(string frameJson, CancellationToken ct = default) | Task | Sends a raw client event JSON frame. |
FinishAsync(CancellationToken ct = default) | Task | Gracefully ends the session according to FinishMode. |
AbortAsync() | Task | Immediately closes the connection and discards in-flight results. |
DisposeAsync() | ValueTask | Asynchronously releases client resources. |
Events
| Event | Type | Trigger |
|---|---|---|
SessionReady | EventHandler<string?> | Session is ready; argument is session.id. |
SourceTranscriptUpdated | EventHandler<QwenTranscriptEventArgs> | The source transcript was updated. |
SourceTranscriptCompleted | EventHandler<QwenTranscriptEventArgs> | Final transcript of a source speech utterance. |
TranslationTextDelta | EventHandler<QwenTextDeltaEventArgs> | The translation text was updated. |
TranslationCompleted | EventHandler<QwenTranscriptEventArgs> | Complete translated text for the sentence. |
TranslatedAudioChunk | EventHandler<QwenAudioChunkEventArgs> | Translated audio chunk. |
TranslatedAudioCompleted | EventHandler | All translated audio for the current turn has been delivered. |
ResponseCompleted | EventHandler<QwenResponseSummary> | Received response.done with status and session cumulative usage. |
RawServerEvent | EventHandler<QwenServerEventArgs> | Raw server event. |
ErrorOccurred | EventHandler<DashScopeErrorEventArgs> | Server error or connection failure. |
Properties
| Property | Type | Description |
|---|---|---|
SessionId | string? | Server session ID. |
FinishMode | QwenRealtimeFinishMode | Actual finish mode used for the session. |
Result objects
QwenTranscriptEventArgs
| Property | Type | Description |
|---|---|---|
Text | string | In SDK 1.1.1, SourceTranscriptUpdated returns the current transcript for qwen3.5-livetranslate-flash-realtime but can return an empty string for qwen3.8-livetranslate-flash-realtime. SourceTranscriptCompleted returns the final source transcript for the sentence, and TranslationCompleted returns its full translation. |
ItemId | string? | Item ID. |
QwenTextDeltaEventArgs
| Property | Type | Description |
|---|---|---|
Delta | string | For qwen3.5-livetranslate-flash-realtime, interim translations can repeat. Do not concatenate them; read TranslationCompleted.Text for the full translation. For qwen3.8-livetranslate-flash-realtime, response.text.delta contains new text that you can append in arrival order. |
ItemId | string? | Item ID. |
QwenAudioChunkEventArgs
| Property | Type | Description |
|---|---|---|
Pcm | byte[] | PCM bytes of the translated audio. The sample rate depends on the session configuration and the audio returned by the server. |
QwenResponseSummary
| Property | Type | Description |
|---|---|---|
Status | string? | Response status, such as completed, failed, or incomplete. |
FailureReason | string? | Reason for failure; null on successful completion. |
TotalTokens | int? | Total tokens accumulated in the current session. |
InputTokens | int? | Input tokens. |
OutputTokens | int? | Output tokens. |
AudioInputTokens | int? | Audio input tokens. |
AudioOutputTokens | int? | Audio output tokens. |
QwenServerEventArgs
| Property | Type | Description |
|---|---|---|
Type | string? | Server event type. |
Root | JsonObject | Complete server event as a JSON object. |
Shared types
DashScope.DashScopeErrorEventArgs
| Property | Type | Description |
|---|---|---|
|
| SDK error code |
|
| Server error code |
|
| Server error message |
|
| ID of the current task |
|
| Underlying exception |
DashScope.Speech.SynthesisUsage
| Property | Type | Description |
|---|---|---|
|
| Input tokens |
|
| Output tokens |
|
| Total tokens |
|
| Character count returned by the server |
DashScope.Transcription.FunAsrTaskStatus
| Member | Description |
|---|---|
Pending | Queued. |
Running | Processing. |
Succeeded | Succeeded. |
Failed | Failed. |
Canceled | Canceled. |
Unknown | Task does not exist or status is unknown. |
DashScope.Qwen.QwenTurnDetectionMode
| Member | Description |
|---|---|
ServerVad | Server detects speech start and end. |
SmartTurn | Semantic turn detection (supported by some models). |
PushToTalk | Client calls CommitAudioAsync and CreateResponseAsync to control turns. |
DashScope.QwenRealtimeFinishMode
| Member | Description |
|---|---|
FinishWithoutWait | Sends session.finish and disconnects immediately. |
CloseOnly | Closes the connection directly. |
FinishAndWait | Sends session.finish and waits for session.finished. |