Open a full-duplex voice session over WebSocket and receive subtitles and audio.
Prerequisites
Install C# SDK 1.2.0 and configure your API key. Replace WorkspaceId with your workspace ID in Singapore. Qwen-Audio-Live requires a workspace-specific domain.
Prepare input.pcm as 16 kHz, 16-bit little-endian, mono raw PCM. You can use FFmpeg to convert a recording.
Quick start
Create a .NET console project, add the SDK, and save the code as Program.cs. Run it with dotnet run.
reply.pcm contains 24 kHz, 16-bit little-endian, mono audio. The example allows 30 seconds for the reply. In your app, wait for the full reply before closing the session.
Session options
| Option | Description |
|---|---|
Model | Model ID for the connection. Use qwen-audio-3.1-live. |
FrontModel | Model that talks to the user. The example uses qwen-audio-4.0-realtime-preview. |
TurnDetectionMode | The example uses duplex so the model can keep listening while it speaks. |
Voice | Choose a voice supported by the frontend model. The example uses yunshu. |
Delegation | The example uses Client mode. Set the backend model when you use Responses mode. |
Methods and events
| Method | Purpose |
|---|---|
ConnectAsync | Open the connection, wait for session.created, and send session.update. |
AppendAudioAsync | Send an audio frame. |
MuteInputAsync / UnmuteInputAsync | Mute or unmute input. |
SendUserTextAsync / SendItemAsync | Add text or a custom item to the session. |
SendFunctionCallOutputAsync | Submit the result of a frontend function call. |
SendThinkingAsync / SendInstructionAsync / SendCommentaryAsync | Send task progress, instructions, or commentary to the frontend model. |
AppendBackendItemAsync / CreateBackendResponseAsync | Append an item to the backend or trigger a backend response. |
SendRawEventAsync | Send a Live client event. |
FinishAsync | Send session.close, wait for session.closed, and disconnect. |
AbortAsync | Disconnect immediately. Final session usage may still be pending. |
| Event or callback | Description |
|---|---|
SessionReady | Fires when the session ID is available. Wait for session.updated before sending audio. |
UserTranscriptDelta / AssistantTextDelta | User transcript or assistant subtitle deltas. |
AssistantAudioChunk | A chunk of reply audio. |
DelegationCreated | A delegation summary. |
BackendEvent | A backend event in Responses mode. |
FunctionCall | A frontend function call. |
UsageUpdated / Closed | A usage update or session closure. The close event includes final usage. |
RawServerEvent / ErrorOccurred | Other server events or errors. |
- The delegation summary contains
DelegationId,TaskId,Summary,OffsetMs, andContext. Use the delegation ID when sending task progress. Usageexposes the latest usage, includingSecondsand the context window usage ratio when available. On normal closure,session.closedreports final usage.
session.input_audio.append. See WebSocket connection and Server events for the protocol and event fields.