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 |
|---|---|---|
StartAsync(CancellationToken ct = default) | Task | Connect and wait for task-started. |
SendAudioAsync(ReadOnlyMemory<byte> pcmFrame, CancellationToken ct = default) | Task | Send an audio frame after startup. |
StopAsync(CancellationToken ct = default) | Task | Send finish-task and await the final results and task-finished. Repeated calls reuse the completed task. |
CancelAsync() | Task | Immediately close the connection. Repeated calls are allowed. |
TranscribePcmStreamAsync(Stream pcm, int frameMilliseconds = 20, CancellationToken ct = default) | Task<IReadOnlyList<RecognitionSentence>> | Read a PCM stream, send frames, and return final sentences. Frames default to 20 ms. |
DisposeAsync() | ValueTask | Release client resources. |
SendContextAsync(JsonArray context, CancellationToken ct = default) | Task | Qwen-Audio-ASR-Message: Send the protocol context array. |
Events
| Event | Type | Description |
|---|---|---|
TranscriberStarted | EventHandler | Task started. |
SentenceBegin | EventHandler<RecognitionSentenceEventArgs> | Sentence start. |
PartialResult | EventHandler<RecognitionSentenceEventArgs> | Intermediate recognition result. |
SentenceEnd | EventHandler<RecognitionSentenceEventArgs> | Final recognition result for a sentence. |
Completed | EventHandler<TranscriptionCompletedEventArgs> | Task finished. |
Failed | EventHandler<DashScopeErrorEventArgs> | 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 |
|---|---|---|
FunAsrSpeechTranscriber.TaskId | string | Identifier. |
RecognitionSentenceEventArgs
| Property | Type | Description |
|---|---|---|
Sentence | RecognitionSentence | Sentence details. |
RawPayload | JsonObject? | Original response JSON. |
RecognitionSentence
| Property | Type | Description |
|---|---|---|
SentenceId | int | Identifier. |
BeginTimeMs | long | Start time in milliseconds. |
EndTimeMs | long? | End time in milliseconds; may be absent before finalization. |
Text | string | Text. |
IsBegin | bool | Whether this is a sentence start. |
IsEnd | bool | Whether this is the final result for a sentence. |
ChannelId | int | Audio channel index; channel numbering starts at 0. |
SpeakerId | string? | Speaker identifier. |
Words | IReadOnlyList<RecognitionWord> | Word details. |
StashText | string? | Stashed recognition text. |
RequestId | string? | Identifier. |
RecognitionWord
| Property | Type | Description |
|---|---|---|
BeginTimeMs | long | Start time in milliseconds. |
EndTimeMs | long? | End time in milliseconds; may be absent before finalization. |
Text | string | Text. |
Punctuation | string | Punctuation. |
Fixed | bool? | Whether the word is finalized. |
SpeakerId | string? | Speaker identifier. |
TranscriptionCompletedEventArgs
| Property | Type | Description |
|---|---|---|
UsageDurationSeconds | float? | Audio duration in seconds (usage.duration). |
RawPayload | JsonObject? | Original response JSON. |
CosyVoiceSpeechSynthesizer
Methods
ct (CancellationToken, optional): cancels the current asynchronous call.
| Method | Returns | Description |
|---|---|---|
StartAsync(CancellationToken ct = default) | Task | Connect and wait for task-started. |
SendTextAsync(string text, CancellationToken ct = default) | Task | Append a text segment after startup. |
StopAsync(CancellationToken ct = default) | Task | Send finish-task and await the final results and task-finished. Repeated calls reuse the completed task. |
CancelSynthesisKeepConnectionAsync(CancellationToken ct = default) | Task | Cancel synthesis with input.directive=cancel and wait for task-finished, without actively closing the connection. |
CancelAsync() | Task | Immediately close the connection. Repeated calls are allowed. |
StreamAudioAsync(IEnumerable<string> segments, TimeSpan? sendInterval = null, CancellationToken ct = default) | IAsyncEnumerable<ReadOnlyMemory<byte>> | Send text segments and yield audio chunks. sendInterval=null uses 200 ms; TimeSpan.Zero sends without waiting. |
SynthesizeAsync(IEnumerable<string> segments, TimeSpan? sendInterval = null, CancellationToken ct = default) | Task<byte[]> | Collect all audio from StreamAudioAsync into one byte array; the same sendInterval rules apply. |
DisposeAsync() | ValueTask | Release client resources. |
Events
| Event | Type | Description |
|---|---|---|
SynthesisStarted | EventHandler | Task started. |
AudioReceived | EventHandler<ReadOnlyMemory<byte>> | Audio bytes in order; append chunks to form the output file. |
SentenceProgress | EventHandler<SynthesisSentenceEventArgs> | Sentence synthesis progress: begin, synthesis, and end. |
SynthesisCompleted | EventHandler | Task finished. |
Failed | EventHandler<DashScopeErrorEventArgs> | Task failure or unexpected disconnection. |
Results
| Property | Type | Description |
|---|---|---|
CosyVoiceSpeechSynthesizer.TaskId | string | Identifier. |
CosyVoiceSpeechSynthesizer.Usage | SynthesisUsage? | Qwen-Audio-TTS: Final task usage. After SynthesizeAsync or StopAsync returns, read InputTokens, OutputTokens, and TotalTokens for the input, output, and total token counts, and Characters for the character count. Usage is null if the server returns no usage. qwen-audio-3.1-tts-flash is billed by token; qwen-audio-3.1-tts-plus is billed by character but also returns token counts.CosyVoice: Final task usage. After SynthesizeAsync or StopAsync returns, read Characters for the total character count. Usage is null if the server returns no usage. |
SynthesisSentenceEventArgs
| Property | Type | Description |
|---|---|---|
Phase | SynthesisSentencePhase | Begin / Synthesis / End. Sentence synthesis progress: begin, synthesis, and end. |
SentenceIndex | int | Identifier. |
OriginalText | string? | Original input text. |
NormalizedText | string? | Normalized synthesis text. |
BilledCharacters | int? | usage.characters returned by the service. |
Words | JsonNode? | Word details. |
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 |
|---|---|---|
SubmitAsync(FileTranscriptionRequest request, CancellationToken ct = default) | Task<FileTranscriptionSubmission> | Submits an asynchronous transcription task and returns TaskId immediately without waiting for completion. |
QueryAsync(string taskId, CancellationToken ct = default) | Task<FileTranscriptionResult> | Queries the current status and subtask list of a task once. |
WaitForCompletionAsync(string taskId, IProgress<FileTranscriptionResult>? status = null, TimeSpan? timeout = null, TimeSpan? pollInterval = null, CancellationToken ct = default) | Task<FileTranscriptionResult> | Polls until the task reaches a terminal state (Succeeded, Failed, or Canceled), or throws on timeout. |
DownloadTranscriptionAsync(string transcriptionUrl, CancellationToken ct = default) | Task<TranscriptionFile> | Downloads and parses the transcription result JSON file from a subtask TranscriptionUrl. |
TranscribeAsync(FileTranscriptionRequest request, IProgress<FileTranscriptionResult>? status = null, CancellationToken ct = default) | Task<IReadOnlyList<FileTranscriptionOutput>> | Submits, polls, and downloads all succeeded subtask results in one call; throws if the overall task fails or all subtasks fail. |
CancelTaskAsync(string taskId, CancellationToken ct = default) | Task | Cancels a queued task (only supported while Pending). |
Dispose() | void | 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 |
|---|---|---|
TranscribeAsync(FlashTranscriptionRequest request, CancellationToken ct = default) | Task<FlashTranscriptionResult> | Performs a single synchronous transcription request and returns the final result. |
TranscribeStreamingAsync(FlashTranscriptionRequest request, CancellationToken ct = default) | IAsyncEnumerable<FlashTranscriptionResult> | Streams interim and final sentence results frame by frame via SSE. |
Dispose() | void | 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 |
|---|---|---|
Code | int | SDK error code |
ServerErrorCode | string? | Server error code |
ServerErrorMessage | string? | Server error message |
TaskId | string? | ID of the current task |
InnerException | Exception? | Underlying exception |
DashScope.Speech.SynthesisUsage
| Property | Type | Description |
|---|---|---|
InputTokens | int? | Input tokens |
OutputTokens | int? | Output tokens |
TotalTokens | int? | Total tokens |
Characters | int? | 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. |