All Products
Search
Document Center

Alibaba Cloud Model Studio:Qwen-Audio-ASR-Message Real-Time Speech Recognition iOS SDK

Last Updated:Sep 24, 2026

This guide shows you how to use the Qwen-Audio-3.1-ASR-Flash-Message real-time speech recognition iOS SDK to transcribe speech into text.

Quick start

  1. Get an API key: Obtain an API key

  2. Download the SDK and run the sample code:
    • Download the latest SDK package.
    • Extract the ZIP package and add the included nuisdk.xcframework to your project.
    • In Build Phases → Link Binary With Libraries, add nuisdk.xcframework.
    • In General → Frameworks, Libraries, and Embedded Content, set nuisdk.xcframework to Embed & Sign.
    • Open the sample project in Xcode. The sample code is in DashFunAsrSpeechTranscriberViewController.m. Replace the API key with your own to try out the feature.

Call sequence

  1. Initialize the SDK.
  2. Set parameters for your use case: use the nui_initialize API to set Connection and control parameters, and use the nui_set_params API to set Recognition quality parameters.
  3. Call nui_dialog_start to start the recognition process.
  4. In the onNuiAudioStateChanged callback, open the recording device based on the audio state.
  5. In the onNuiNeedAudioData callback, continuously supply recording data, or call nui_update_audio_data to actively push recording data.
  6. In the onNuiEventCallback callback, listen for events and retrieve speech recognition results.
  7. Call nui_dialog_cancel to stop recognition, and confirm that recognition has finished by listening for the EVENT_TRANSCRIBER_COMPLETE event.
  8. When you no longer need the recognition feature, call nui_release to release the SDK resources.

Request parameters

Connection and control parameters

Configure these parameters by passing a JSON string in the parameters argument of the nui_initialize API.

Example parameters: The following JSON string is an example and does not list all parameters. Add the parameters you need when you write your code:

{
    "url": "wss://dashscope.aliyuncs.com/api-ws/v1/inference",
    "apikey": "st-****",
    "device_id": "my_device_id",
    "service_mode": "1"
}
Parameter descriptions
ParameterTypeRequiredDescription
urlStringYes

Service address:

  • wss://dashscope.aliyuncs.com/api-ws/v1/inference

  • China (Beijing): wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference

  • Singapore: wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/inference

Replace {WorkspaceId} with your actual Workspace ID.

apikeyStringYesAPI key.
service_modeStringYesRun mode. Fixed to "1" for real-time speech recognition.
device_idStringYesA unique string that identifies the end user. You can set it to an in-app user ID or a device identifier generated on the client. This ID is used mainly for log tracing and troubleshooting.
audio_update_manuallyStringNo

Whether to enable active audio data pushing. Default: "false".

If set to "true" and the SDK version supports on-device audio processing capabilities such as AEC or VAD, those capabilities are enabled by default.

workspaceStringNoThe path where on-device resource files are stored. This parameter is required when audio_update_manually is set to "true" and an on-device audio processing capability such as AEC or VAD is enabled.
debug_pathStringNo

Storage path for the log file.

This parameter takes effect only when save_log is set to YES in the nui_initialize API. In that case, you must set the log file path, otherwise an error occurs.

At most two log files are kept locally.

save_wavStringNo

Whether to save an audio file for debugging. The audio file is saved under debug_path.

Default: "false".

Valid values:

  • "true": save the file.

  • "false": do not save the file.

This parameter takes effect only when save_log is set to true in the nui_initialize API. In addition, debug_path must also be set.

max_log_file_sizeintNo

Maximum size of the log file, in bytes.

This parameter takes effect only when save_log is set to YES in the nui_initialize API.

Default: 104857600 (100 * 1024 * 1024 bytes, that is, 100 MiB).

log_track_levelintNo

Filter level for the log content sent through the log callback (onNuiLogTrackCallback).

Default: 2.

Valid values:

  • 0: LOG_LEVEL_VERBOSE

  • 1: LOG_LEVEL_DEBUG

  • 2: LOG_LEVEL_INFO

  • 3: LOG_LEVEL_WARNING

  • 4: LOG_LEVEL_ERROR

  • 5: LOG_LEVEL_NONE (disables this feature)

Note: log_track_level and level (set through the nui_initialize API) together determine which logs are ultimately sent to the callback. A log is sent to the callback only when its level value is greater than or equal to both log_track_level and level. For example, if log_track_level is set to 2 (INFO) and level is set to 3 (WARNING), then only logs at WARNING level or higher (value >= 3) are sent to the callback.

Recognition quality parameters

Configure these parameters by passing a JSON string in the params argument of the nui_set_params API.

Example parameters: The following JSON string is an example and does not list all parameters. Add the parameters you need when you write your code:

{
    "service_type": 4,
    "nls_config": {
        "model": "qwen-audio-3.1-asr-flash-message",
        "sr_format": "pcm",
        "sample_rate": "16000"
    }
}
Parameter descriptions
Top-level parameterTypeRequiredDescription
service_typeintYesSpeech service type. Fixed to 4 for real-time speech recognition.
nls_configobjectYesThe core recognition configuration object. It contains key parameters such as model selection and recognition quality controls.
nls_config.modelstringYesThe model name. Set to qwen-audio-3.1-asr-flash-message.
nls_config.sr_formatstringYes

The audio format.

Valid values:

  • pcm
  • opus

ImportantIf you provide PCM audio data and set this parameter to opus, the SDK encodes the data into Opus internally.

nls_config.sample_rateintYes

The sample rate, in Hz.

Only 16000 Hz is supported.

nls_config.max_sentence_silenceintNo

The VAD silence threshold for segmentation, in ms. When the silence after a segment of speech exceeds this threshold, the system determines that the sentence has ended.

Default value: 1300.

Valid values: [200, 6000].

nls_config.heartbeatbooleanNo

Whether to enable heartbeat packets.

Default value: false.

  • true: Keeps the connection to the server alive even when silent audio is sent continuously.
  • false (default): Even when silent audio is continuously sent, the connection times out and closes after a period of time.

Silent audio refers to content in an audio file or data stream that contains no sound signal. You can generate silent audio in several ways, such as using audio editing software like Audacity or Adobe Audition, or using a command-line tool like FFmpeg.

nls_config.disfluency_removal_enabledbooleanNoWhether to filter filler words and polish the output. Defaults to false. Set to true to enable this feature.
nls_config.intermediate_result_enabledbooleanNoWhether to return intermediate streaming results. Defaults to false. Set to true to return intermediate streaming results.
nls_config.vocabulary_idstringNo

The ID of a precompiled hot word list.

Generate this ID in advance by calling the create hot word list API. Pass the ID during recognition to use the hot words in the list.

Suitable for scenarios where the vocabulary is known and relatively stable, and where you need to reuse the same word list across requests.

For usage details, see Precompiled hotwords.

nls_config.instant_vocabularyobjectNo

Instant hot words.

Passed as key-value pairs, where the key is the hot word text (string) and the value is the hot word weight (integer). No hot word list needs to be created in advance. The weight ranges from [1, 5] or is set to 50: a value in [1, 5] makes the model more likely to output the word as the value increases; a value of 50 designates a super hot word, which greatly improves recall, but the number of super hot words cannot exceed 50.

Suitable for temporary, session-level hot word optimization.

When instant and precompiled hotwords are configured together, the system merges both sets. If the merged set contains more than 2000 hotwords, the system randomly selects 2000 to use. For usage, supported models, and limits, see Instant hotwords.

nls_config.speech_noise_thresholdfloatNo

The threshold for distinguishing speech from noise, used to adjust the sensitivity of Voice Activity Detection (VAD).

Valid values: [-1.0, 1.0].

Value descriptions:

  • The closer the value is to -1: The noise threshold decreases, so noise is more likely to be recognized as speech, which may cause more noise to be transcribed.
  • The closer the value is to +1: The noise threshold increases, so speech is more likely to be misjudged as noise, which may cause some speech to be filtered out.

This is an advanced configuration parameter. Adjusting it can significantly affect recognition results. Recommendations:

  • Thoroughly test and verify the results before adjusting.
  • Adjust in small increments based on the actual audio environment (a step of 0.1 is recommended).
nls_config.enable_connection_fast_checkBOOLNoWhether to enable fast network checks so that disconnections can be reported as soon as possible. Default: NO.

Key APIs

NeoNui

nui_initialize

Initializes the speech recognition 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
ParameterTypeDescription
parameterschar*A JSON string that contains authentication, connection, and debugging parameters. See Connection and control parameters.
levelNuiSdkLogLevelPrint level for the SDK's own logs.
save_logBOOLWhether to save logs locally. If set to YES, specify a path with debug_path in Connection and control parameters, and optionally set the file size with max_log_file_size.
Return value

Returns an error code. See Error code reference.

nui_set_params

Sets the Recognition quality parameters in JSON format. Call this method before nui_dialog_start.

Method signature
-(NuiResultCode) nui_set_params:(const char *)params;
Parameter descriptions
ParameterTypeDescription
paramschar*Recognition quality parameters.
Return value

Returns an error code. See Error code reference.

nui_dialog_start

Starts recognition.

Method signature
-(NuiResultCode) nui_dialog_start:(NuiVadMode)vad_mode
                      dialogParam:(const char *)dialog_params;
Parameter descriptions
ParameterTypeDescription
vad_modeNuiVadModeVAD mode. Fixed to MODE_P2T.
dialog_paramschar*

If the apikey parameter in Connection and control parameters is a temporary API key, you can update it here when it expires. You can also provide context here to improve recognition accuracy through context enhancement.

The content is in JSON format:

{
  "apikey": "st-****",
  "input_context": [
    {
      "role": "user",
      "content": [
        {
          "text": "xxxxx",
          "type": "input_text"
        }
      ]
    }
  ]
}
Return value

Returns an error code. See Error code reference.

nui_dialog_cancel

Ends recognition or cancels the current interaction immediately.

Method signature
-(NuiResultCode) nui_dialog_cancel:(BOOL)force;
Parameter descriptions
ParameterTypeDescription
forceBOOL

Whether to end forcibly and discard the final result.

  • YES: End the task immediately without waiting for the server to return the final recognition result.

  • NO: End the task, but wait for the complete result to return.

Return value

Returns an error code. See Error code reference.

nui_dialog_action

Sends a dialog action during an interaction to update the recognition context or other runtime behavior.

Method signature
-(NuiResultCode) nui_dialog_action:(const char *)action_params;
Parameter descriptions
ParameterTypeDescription
action_paramschar*A JSON string used to update the recognition context or other runtime behavior.
action_params.typeStringFixed to "action".
action_params.commandString

Runtime command. Valid values:

  • context: Updates the context enhancement immediately to improve recognition accuracy.

  • play_start: When on-device AEC is used, notifies the internal AEC player that audio playback has started.

  • play_over: When on-device AEC is used, notifies the internal AEC player that audio playback has ended.

action_params.contextString

When command is "context", provides the context enhancement to update immediately. Example:

{
  "context": [
    {
      "role": "user",
      "content": [
        {
          "text": "xxx",
          "type": "input_text"
        }
      ]
    }
  ]
}
Return value

Returns 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.

Method signature
-(NuiResultCode) nui_update_audio_data:(const char *)data
                                    Len:(int)length
                              FirstPack:(BOOL)first_pack;
Parameter descriptions
ParameterTypeDescription
dataconst char *The audio data to push.
lengthintThe length of the audio data, in bytes.
first_packBOOLYou do not need to use this parameter.
Return value

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.

Method signature
-(NuiResultCode) nui_push_reference_data:(const char *)data
                                     Len:(int)length
                               FirstPack:(BOOL)first_pack;
Parameter descriptions
ParameterTypeDescription
dataconst char *The audio data to push.
lengthintThe length of the audio data, in bytes.
first_packBOOLYou do not need to use this parameter.
Return value

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.

Method signature
-(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 events and speech recognition results

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
ParameterTypeDescription
nuiEventNuiCallbackEventCallback event.
dialoglongSession ID. You do not need to use this parameter.
wuwchar*Voice wake-up. You do not need to use this parameter.
asr_resultchar*Speech recognition result.
finishBOOLWhether the current recognition round has finished.
codeintError 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
ParameterDescription
STATE_OPENThe interaction has started. You can open the recording device and start recording.
STATE_PAUSEThe interaction has stopped. You can stop recording.
STATE_CLOSEThe SDK instance has been released. You can close the recording device completely.

onNuiNeedAudioData: supply audio data for recognition

After recognition starts, this callback is triggered continuously. Supply the audio data to be recognized in it.

Method signature
-(int) onNuiNeedAudioData:(char *)audioData length:(int)len;
Parameter descriptions
ParameterTypeDescription
audioDatachar *The audio data to supply.
lenintThe 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
ParameterTypeDescription
nuiEventNuiCallbackEventThe callback event.
infochar *You do not need to use this parameter.
info_lenintYou do not need to use this parameter.
bufferchar *Auxiliary data, such as audio data after AEC processing.
lenintThe 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

EventDescription
EVENT_TRANSCRIBER_STARTEDThe task started successfully.
EVENT_VAD_STARTTriggered right after the task starts. It does not mean that the start of speech has been detected.
EVENT_VAD_ENDThe end of speech was detected.
EVENT_ASR_PARTIAL_RESULTAn intermediate speech recognition result.
EVENT_ASR_ERRORAn error occurred during speech recognition.
EVENT_MIC_ERRORTriggered because no audio data was received for 2 consecutive seconds.
EVENT_SENTENCE_ENDThe end of a sentence was detected. A complete recognition result for the sentence is returned.
EVENT_TRANSCRIBER_COMPLETESpeech recognition finished.
EVENT_AEC_DATAAudio data after acoustic echo cancellation (AEC) processing.