Qwen-Audio-3.0-ASR-Flash/Fun-ASR-Flash non-real-time speech recognition iOS SDK converts speech to text.
User guide: Non-real-time speech recognition. For supported audio formats, file size limits, duration limits, and other input requirements, see Audio specifications.
Quick start
- Get an API key: Get an API key
- Download the SDK and run the sample code:
- Download the latest SDK bundle.
- Extract the ZIP archive and add nuisdk.framework to the project.
- Add nuisdk.xcframework in Build Phases → Link Binary With Libraries.
- In General → Frameworks, Libraries, and Embedded Content, set nuisdk.xcframework to Embed & Sign.
- Open the sample project in Xcode. The sample code is in
DashFunAsrFlashFileTranscriberViewController.m. Replace the API key to try the feature.
Call procedure
Synchronous mode
-
Initialize the SDK
-
Configure the parameters based on your business requirements
-
Call
nui_file_trans_startto send a non-real-time speech recognition request. -
Use
onFileTransEventCallbackto listen for theEVENT_FILE_TRANS_RESULTevent and obtain the final recognition result -
Call
nui_releaseto release SDK resources
Request parameters
Connection and control parameters
Pass a JSON string to the nui_initialize method's parameters parameter to configure these settings.
Parameter example: The following JSON string is an example and does not list all parameters. Add parameters as needed in your code:
{
"url": "wss://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
"apikey": "st-****",
"device_id": "my_device_id",
"service_mode": "1"
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | String | Yes | Service endpoints:
Replace {WorkspaceId} with your actual Workspace ID. |
apikey | String | Yes | API Key. |
service_mode | String | Yes | The operating mode. For non-real-time speech recognition, set this parameter to |
device_id | String | Yes | A unique string that identifies the end user. You can use an in-app user ID or a client-generated unique device identifier. This ID is mainly used for log tracing and troubleshooting. |
debug_path | String | No | The path for log files. This parameter takes effect only when you call nui_initialize with |
max_log_file_size | int | No | The maximum log file size in bytes. This parameter takes effect only when you call nui_initialize with |
log_track_level | int | No | The filtering level for logs sent through the logging callback (onFileTransLogTrackCallback). 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: |
Recognition parameters
Use nui_file_trans_start to configure all recognition parameters.
Parameter example: The following JSON string is an example and does not list all parameters. Add parameters as needed in your code:
{
"apikey": "st-****",
"messages": [
{
"content": [
{
"input_audio": {
"data": "{YOUR_AUDIO_URL}"
},
"type": "input_audio"
}
],
"role": "user"
}
],
"nls_config": {
"format": "mp3",
"model": "qwen-audio-3.0-asr-flash"
}
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
apikey | string | No | If Connection and control parameters |
nls_config | object | Yes | The core speech recognition configuration object, including the model and parameters that control recognition. |
nls_config.model | string | Yes | The model name. Qwen-Audio-3.0-ASR-Flash and Fun-ASR-Flash models are supported. For details, see Supported models and regions. |
nls_config.format | string | Yes | The audio format. Set this parameter to the actual format. Supported formats include |
nls_config.sample_rate | string | No | The audio sample rate in Hz. For example, |
nls_config.vocabulary_id | string | No | The precompiled vocabulary ID. Create a vocabulary in advance and pass its ID during recognition to use its hotwords. Use this option when the vocabulary is known, relatively stable, and reused across requests. For usage instructions, see Precompiled hotwords. |
nls_config.instant_vocabulary | object | No | Instant hotwords. ImportantOnly |
nls_config.language_hints | array[string] | No | The language codes for recognition. If the language is unknown in advance, omit this parameter to let the model detect it automatically.
|
messages | array[object] | Yes | The list of messages. It contains the audio to recognize and optional conversation context to improve recognition. |
ImportantContext improves the recognition accuracy of specialized terms. For usage instructions, see Context enhancement.
Constraints: Context messages (input_text and text types) are limited to five each. If the limit is exceeded, only the five most recent messages are retained. The total context text length per turn (the sum of the user and assistant text field lengths) must not exceed 400 characters. Each character counts as one. Excess characters are truncated from the end.
ImportantWhen context is included, messages messages must follow a specific order. Arrange context messages by conversation turn. Within each turn, user (input_text type) must precede the corresponding assistant (text type). The input_audio user message containing input audio must be placed at the end of messages .
| Parameter | Type | Required | Description |
|---|---|---|---|
role | string | Yes | The message role. Valid values:
|
content | array[object] | Yes | The list of message content. See the following descriptions. |
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | The content type. Each request requires at least one
|
input_audio | object | No | Required when |
input_audio.data | string | Yes | The audio data to recognize. For supported audio formats, file size limits, duration limits, and other input requirements, see Audio specifications. The following two input methods are supported:
Example (URL): https://example.com/audio/sample.wavExample (Base64): data:audio/wav;base64,{BASE64_ENCODED_DATA} |
text | string | No | Required when |
Key interfaces
NeoNui
nui_initialize
Initialize the speech recognition SDK instance. The SDK uses a singleton. Do not initialize it again before calling nui_release .
- (NuiResultCode) nui_initialize:(const char *)parameters
logLevel:(NuiSdkLogLevel)level
saveLog:(BOOL)save_log;
Parameters
| Parameter | Type | Description |
|---|---|---|
parameters | char* | A JSON string containing authentication, connection, and debugging parameters. See Connection and control parameters. |
level | NuiSdkLogLevel | The level of logs printed by the SDK. |
save_log | BOOL | Whether to save logs locally. If set to |
Returns an error code. See Error codes.
nui_set_params
Use this method to set or update nls_config separately. You do not need to call this method if all parameters are provided in nui_file_trans_start in a single call.
- (NuiResultCode) nui_set_params:(const char *)params;
Parameters
| Parameter | Type | Description |
|---|---|---|
params | char* | Recognition parameters in |
Returns an error code. See Error codes.
nui_file_trans_start
Start recognition.
Method signature- (NuiResultCode) nui_file_trans_start:(const char *)params
taskId:(char *)task_id;
Parameters
| Parameter | Type | Description |
|---|---|---|
params | char* | Recognition parameters. Example: |
task_id | char* | You can ignore this parameter and pass null. |
Returns an error code. See Error codes.
nui_file_trans_query
This non-real-time speech recognition feature only supports synchronous requests. You can ignore this method.
Method signature- (NuiResultCode) nui_file_trans_query:(const char *)task_id;
Parameters
| Parameter | Type | Description |
|---|---|---|
task_id | char* | The ID of the task to query, obtained from EVENT_FILE_TRANS_UPLOADED. |
Returns an error code. See Error codes.
nui_file_trans_cancel
Immediately cancel the current task.
Method signature- (NuiResultCode) nui_file_trans_cancel:(const char *)task_id;
Parameters
| Parameter | Type | Description |
|---|---|---|
task_id | char* | The ID of the task to cancel, obtained from EVENT_FILE_TRANS_UPLOADED. |
Returns an error code. See Error codes.
nui_release
Release all internal SDK resources and forcibly stop all ongoing tasks. After this call, the SDK instance becomes unavailable. To use it again, call nui_initialize to initialize it again.
- (NuiResultCode) nui_release;
Return value
Returns an error code. See Error codes.
nui_get_version
Get the current SDK version.
Method signature- (const char*) nui_get_version;
Return value
The current SDK version.
NeoNuiSdkDelegate: Callbacks
onFileTransEventCallback: Listen for events and recognition results
Method signature- (void) onFileTransEventCallback:(NuiCallbackEvent)nuiEvent
asrResult:(const char *)asr_result
taskId:(const char *)task_id
ifFinish:(BOOL)finish
retCode:(int)code;
Parameters
| Parameter | Type | Description |
|---|---|---|
nuiEvent | NuiCallbackEvent | The callback event. |
asr_result | char* | The speech recognition result. |
task_id | char* | The task ID. |
finish | BOOL | Whether recognition for this turn has finished. |
code | int | The error code, valid when an EVENT_ASR_ERROR event occurs. See Error codes. |
onFileTransLogTrackCallback: Listen for tracing logs
This callback receives detailed internal SDK logs for troubleshooting and debugging.
- (void)onFileTransLogTrackCallback:(NuiSdkLogLevel)level
logMessage:(const char *)log;
NuiCallbackEvent: Event types
| Event | Description |
|---|---|
EVENT_FILE_TRANS_CONNECTED | Successfully connected to the service. |
EVENT_FILE_TRANS_UPLOADED | The audio file was uploaded successfully. You can obtain the current task_id at this point. |
EVENT_FILE_TRANS_RESULT | The final recognition result. |
EVENT_ASR_ERROR | An error occurred during speech recognition. |