Use the iOS SDK for Qwen-Audio-3.0-Realtime to build real-time voice conversations with audio input and audio or text output.
User guide: For model introductions and selection advice, see Real-time voice conversation.
Quick start
-
Obtain an API key: Obtain and configure an API key.
-
Download the SDK and run the sample code:
- Download the latest SDK package.
- Extract the ZIP package and add
nuisdk.xcframeworkto your project. - In Build Phases > Link Binary With Libraries, add
nuisdk.xcframework. - In General > Frameworks, Libraries, and Embedded Content, set
nuisdk.xcframeworkto Embed & Sign. - Open the project in Xcode. The sample code is in
DashQwenAudioChatViewController.m. Replace the API key to try the feature.
Call procedure
- Initialize the SDK.
- Set parameters for your use case. Use the
parametersargument of nui_initialize to set the connection and control parameters, and use nui_set_params to set the voice conversation parameters. - Call nui_dialog_start to start the conversation.
- In onNuiAudioStateChanged, start the recording device based on the audio state.
- Continuously supply recording data in onNuiNeedAudioData, or call nui_update_audio_data to actively push recording data.
- Continuously receive the audio returned by the model in onNuiAssistEventCallback.
- Listen for events and obtain event information in onNuiEventCallback.
- Call nui_dialog_cancel to stop the conversation, and listen for
EVENT_TRANSCRIBER_COMPLETEto confirm that it has ended. - When the conversation feature is no longer needed, call nui_release to release the SDK resources.
Request parameters
Connection and control parameters
Pass a JSON string in the parameters argument of nui_initialize.
Example: The following JSON string does not list every parameter. Add parameters as needed for your use case.
{
"url": "wss://dashscope.aliyuncs.com/api-ws/v1/inference",
"apikey": "st-****",
"device_id": "my_device_id",
"service_mode": "1"
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
|
| Yes | Service endpoint:
{WorkspaceId} with your actual Workspace ID. |
|
| Yes | API key. |
|
| Yes | Runtime mode. Set this parameter to |
|
| Yes | A unique string that identifies the end user. You can use an in-app user ID or a client-generated device identifier. This ID is mainly used for log tracing and troubleshooting. |
|
| No | Whether to actively push audio data. Default: |
|
| No | The storage path for on-device resource files. This parameter is required when |
|
| No | The log file storage path. This parameter takes effect only when |
|
| No | Whether to save debug audio under |
|
| No | The maximum log file size in bytes. This parameter takes effect only when |
|
| No | The filter level for logs sent through |
Voice conversation parameters
Pass a JSON string in the params argument of nui_set_params.
Example: The following JSON string does not list every parameter. Add parameters as needed for your use case.
{
"service_type": 4,
"nls_config": {
"model": "qwen-audio-3.0-realtime-plus",
"sr_format": "pcm"
}
}
Parameters
| Top-level parameter | Type | Required | Description |
|---|---|---|---|
|
| Yes | Voice service type. Set this parameter to |
|
| Yes | Core voice conversation configuration, including model selection and conversation behavior. |
|
| Yes | Model name. Supports the |
|
| Yes | Input audio format. Only |
|
| No | A string containing an array of output modalities. Valid values:
|
|
| No | TTS voice. Default: |
|
| No | Whether to enable enhanced emotional expression. When enabled, the response voice has more noticeable emotional variation. Default: |
|
| No | System instructions that define the model's role, response style, and behavioral preferences for the entire session. |
|
| No | Maximum number of historical question-answer turns allowed in a request. Valid values: 1 to 50. Default: |
|
| No | A string containing an array of Function Calling tool definitions. After you configure this parameter, the model decides whether to call a tool based on the user input. Each definition uses |
|
| No | A string containing a JSON object for turn detection. If omitted, the session uses push-to-talk mode, in which audio is committed and inference is triggered manually. If set, duplex conversation mode is enabled. |
|
| No | VAD type. |
|
| No | VAD sensitivity. This parameter applies only to |
|
| No | Minimum silence duration after speech, in milliseconds, before the model response is triggered. This parameter applies only to |
|
| No | A string containing an array of publicly accessible prerecorded audio URLs for the target speaker. This parameter applies only to |
Key APIs
NeoNui
nui_initialize
Initializes the voice conversation SDK instance. The SDK is a singleton. Do not initialize it again before you call nui_release.
Method signature-(NuiResultCode) nui_initialize:(const char *)parameters
logLevel:(NuiSdkLogLevel)level
saveLog:(BOOL)save_log;
Parameter descriptions
Parameter | Type | Description |
|---|---|---|
|
| A JSON string that contains authentication, connection, and debugging parameters. See Connection and control parameters. |
|
| Print level for the SDK's own logs. |
| BOOL | Whether to save logs locally. If set to |
Returns an error code. See Error code reference.
nui_set_params
Sets the Voice conversation parameters in JSON format. Call this method before nui_dialog_start.
Method signature-(NuiResultCode) nui_set_params:(const char *)params;
Parameter descriptions
Parameter | Type | Description |
|---|---|---|
|
|
Returns an error code. See Error code reference.
nui_dialog_start
Starts the conversation.
Method signature-(NuiResultCode) nui_dialog_start:(NuiVadMode)vad_mode
dialogParam:(const char *)dialog_params;
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| VAD mode. Fixed to |
|
| If |
An error code. See Error code reference.
nui_dialog_cancel
Ends the conversation or immediately cancels the current interaction.
Method signature-(NuiResultCode) nui_dialog_cancel:(BOOL)force;
Parameter descriptions
Parameter | Type | Description |
|---|---|---|
|
| Whether to end forcibly and discard the final result.
|
Returns an error code. See Error code reference.
nui_dialog_action
Sends a conversation action command during an interaction to update runtime behavior such as the conversation context.
Method signature- (NuiResultCode) nui_dialog_action:(const char *)params;
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| A JSON string used to update runtime behavior such as the conversation context. |
|
| Set to |
|
| Runtime command. Valid values:
|
|
| Function call request update. Used when |
|
| Event type. This parameter is required when |
|
| Required when |
|
| Optional when |
context.item parameters:
| Parameter | Type | Description |
|---|---|---|
|
| Optional unique conversation item ID. If omitted, the server generates one. An error is returned if the specified ID already exists. |
|
| Required item type. Valid values:
|
|
| Required for |
|
| Required for |
|
| Required for |
|
| Required for |
|
| Required for |
|
| Required for |
context.response parameters:
| Parameter | Type | Description |
|---|---|---|
|
| Output modalities. |
|
| Overrides the TTS voice for this inference. |
Example:
{
"type": "action",
"command": "function_call",
"context": {
"item": {
"call_id": "call_xxxx",
"output": "{\"city\":\"Hangzhou\",\"condition\":\"sunny\",\"temperature\":18}",
"type": "function_call_output"
},
"type": "conversation.item.create"
}
}
{
"type": "action",
"command": "function_call",
"context": {
"response": {
"modalities": ["text", "audio"]
},
"type": "response.create"
}
}
Return value
An error code. See Error code reference.
nui_update_audio_data
When audio_update_manually is set to "true", recording data is no longer supplied through onNuiNeedAudioData. Use this method to actively push it instead.
-(NuiResultCode) nui_update_audio_data:(const char *)data
Len:(int)length
FirstPack:(BOOL)first_pack;
Parameter descriptions
Parameter | Type | Description |
|---|---|---|
|
| The audio data to push. |
|
| The length of the audio data, in bytes. |
|
| You do not need to use this parameter. |
Returns an error code. See Error code reference.
nui_push_reference_data
When audio_update_manually is set to "true" and on-device acoustic echo cancellation (AEC) is enabled, use this method to push the audio played by the player as the reference signal.
-(NuiResultCode) nui_push_reference_data:(const char *)data
Len:(int)length
FirstPack:(BOOL)first_pack;
Parameter descriptions
Parameter | Type | Description |
|---|---|---|
|
| The audio data to push. |
|
| The length of the audio data, in bytes. |
|
| You do not need to use this parameter. |
Returns an error code. See Error code reference.
nui_release
Releases all internal SDK resources and forcibly terminates all running tasks. After you call this method, the SDK instance becomes unavailable. To use it again, you must call nui_initialize to initialize it again.
Method signature-(NuiResultCode) nui_release;
Return value
Returns an error code. See Error code reference.
nui_get_version
Gets the current SDK version. This method returns a value only after nui_initialize is called.
-(const char*) nui_get_version;
Return value
The current SDK version.
nui_get_all_response
Gets the complete information for the current event callback.
Method signature-(const char*) nui_get_all_response;
Return value
The complete event information as a JSON string.
NeoNuiSdkDelegate: callback listeners
onNuiEventCallback: listen for event information
Method signature-(void) onNuiEventCallback:(NuiCallbackEvent)nuiEvent
dialog:(long)dialog
kwsResult:(const char *)wuw
asrResult:(const char *)asr_result
ifFinish:(BOOL)finish
retCode:(int)code;
Parameter descriptions
Parameter | Type | Description |
|---|---|---|
| Callback event. | |
|
| Session ID. You do not need to use this parameter. |
|
| Voice wake-up. You do not need to use this parameter. |
|
| Speech recognition result. |
|
| Whether the current recognition round has finished. |
|
| Error code. Valid when the EVENT_ASR_ERROR event occurs. See Error code reference. |
onNuiAudioStateChanged: listen for the audio state
The SDK uses this callback to notify you when to start or stop recording.
Method signature-(void) onNuiAudioStateChanged:(NuiAudioState)state;
NuiAudioState states
Parameter | Description |
|---|---|
| The interaction has started. You can open the recording device and start recording. |
| The interaction has stopped. You can stop recording. |
| The SDK instance has been released. You can close the recording device completely. |
onNuiNeedAudioData: supply audio data
After the conversation starts, this callback is triggered continuously. Supply the audio data in this callback. You do not need to use this callback when audio_update_manually is set to "true".
-(int) onNuiNeedAudioData:(char *)audioData length:(int)len;
Parameter descriptions
Parameter | Type | Description |
|---|---|---|
|
| The audio data to supply. |
|
| The size of the supplied audio data, in bytes. |
onNuiAssistEventCallback: receive auxiliary data and information
Receives auxiliary events and related data from the SDK.
Method signature-(void) onNuiAssistEventCallback:(NuiCallbackEvent)nuiEvent
info:(char*)info
infoLen:(int)info_len
buffer:(char*)buffer
len:(int)len;
Parameter descriptions
Parameter | Type | Description |
|---|---|---|
|
| The callback event. |
|
| You do not need to use this parameter. |
|
| You do not need to use this parameter. |
|
| Auxiliary data, such as TTS audio returned by the model. |
|
| The length of the auxiliary data, in bytes. |
onNuiLogTrackCallback: listen for tracking logs
This callback receives the SDK's detailed internal logs to help you locate and debug issues.
-(void) onNuiLogTrackCallback:(NuiSdkLogLevel)level
logMessage:(const char *)log;
NuiCallbackEvent: event types
| Event | Description |
|---|---|
| The task started successfully. |
| Triggered immediately after the task starts. This does not mean that the start of speech has been detected. |
| The end of speech was detected. |
| An intermediate speech recognition result. |
| An error occurred during the voice conversation. |
| Triggered when no audio data is received for two consecutive seconds. |
| The end of a sentence was detected and a complete recognition result was returned. |
| The voice conversation ended. |
| An incremental text transcript event for audio output. Transcript segments are returned in streaming mode. |
| The transcript for audio output is complete. |
| Other event information, such as a Function Calling result. |
| The model started returning TTS audio. |
| TTS audio returned by the model. |
| The model finished returning TTS audio. |
| Audio data processed by AEC. |