This guide walks you through the Qwen-Audio-ASR-Filetrans non-real-time speech recognition iOS SDK, so you can convert audio into text.
For input requirements such as supported audio formats, file size limits, and duration limits, see Audio specifications.
Quick start
-
Get an API Key:Obtain an API key
-
Download the SDK and run the sample code:
- Download the latest SDK bundle.
- Unzip the ZIP package and add the included nuisdk.framework to your project.
- Under Build Phases → Link Binary With Libraries, add
nuisdk.xcframework. - Under General → Frameworks, Libraries, and Embedded Content, set
nuisdk.xcframeworkto Embed & Sign. - Open the sample project in Xcode. The sample code is located in
DashFunAsrFileTranscriberViewController.m. Replace the API Key to try out the feature.
Call steps
Synchronous mode
- Initialize the SDK.
- Configure the relevant parameters for your use case.
- Set
async_requesttofalseand callnui_file_trans_startto submit a non-real-time speech recognition request and wait for the result. - In the
onFileTransEventCallbackcallback, listen for theEVENT_FILE_TRANS_RESULTevent to get the final recognition result. - Call
nui_releaseto release the SDK resources.
Asynchronous mode
- Initialize the SDK.
- Configure the relevant parameters for your use case.
- Set
async_requesttotrueand callnui_file_trans_startto submit a non-real-time speech recognition request. - Call
nui_file_trans_queryto actively query the recognition progress or result. - In the
onFileTransEventCallbackcallback, listen for theEVENT_FILE_TRANS_QUERY_RESULTevent to get the current query result. - In the
onFileTransEventCallbackcallback, listen for theEVENT_FILE_TRANS_RESULTevent to get the final recognition result. - Call
nui_releaseto 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 interface.
Example parameters
The following is a sample JSON string. Not all parameters are listed. Add the ones you need when you write your code:
{
"url": "wss://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription",
"apikey": "st-****",
"device_id": "my_device_id",
"service_mode": "1"
}
Parameter descriptions
| Parameter | Type | Required | Description |
|---|---|---|---|
|
| Yes | Service endpoints:
Replace |
|
| Yes | The API Key. |
|
| Yes | The run mode. Fixed to |
|
| Yes | A unique string that identifies the end user. Set it to an in-app user ID or a device identifier generated by the client. This ID is used mainly for log tracing and troubleshooting. |
|
| No | The storage path for the log file. This parameter takes effect only when A maximum of two log files are kept locally. |
|
| No | The maximum size of the log file, in bytes. This parameter takes effect only when Default value: 104857600 (100 * 1024 * 1024 bytes, that is, 100 MiB). |
|
| No | Controls the filter level of the log content sent out through the log callback ( Default value: 2. Valid values:
Note: |
Speech recognition effect parameters
Configure all speech recognition parameters through the nui_file_trans_start interface.
Example parameters
The following is a sample JSON string. Not all parameters are listed. Add the ones you need when you write your code:
{
"apikey": "st-****",
"file_urls": [
"{YOUR_AUDIO_URL}"
],
"async_request": false,
"nls_config": {
"model":"qwen-audio-3.0-asr-flash-filetrans",
"diarization_enabled": false
}
}
Parameter descriptions
| Parameter | Type | Required | Description |
|---|---|---|---|
|
| Yes | A list of URLs of the audio or video files to transcribe. HTTP and HTTPS are supported. A single request supports only one URL. For input requirements such as supported audio formats, file size limits, and duration limits, see Audio specifications. If the recording is stored in Alibaba Cloud OSS, the RESTful API supports temporary URLs prefixed with Important
|
|
| No | Whether the speech recognition request is asynchronous. Default value: Valid values:
|
|
| No | If the |
|
| Yes | The core speech recognition configuration object. It contains key parameters such as model selection and recognition effect controls. |
|
| Yes | The model name. |
|
| No | The sensitive words to process during speech recognition. You can set a different handling method for each sensitive word. For details, see Sensitive word filtering. |
|
| No | The index of the audio tracks to recognize in a multi-track audio file. The index starts at 0. For example, [0] recognizes the first track, and [0, 1] recognizes the first and second tracks at the same time. If you omit this parameter, only the first track is processed. ImportantEach specified track is billed independently. For example, requesting [0, 1] for a single file incurs two separate charges. Default value: [0]. |
|
| No | Whether to enable speaker diarization. Disabled by default. Applies only to mono audio. Multi-channel audio does not support speaker diarization. When enabled, the recognition result includes a NoteWhen speaker diarization is enabled, keep the audio duration within 2 hours. Otherwise, recognition may fail or time out. Default value: false. For an example of |
|
| No | ImportantTakes effect only when speaker diarization is enabled ( A reference value for the number of speakers. The valid range is an integer from 2 to 100 (inclusive). By default, the number of speakers is detected automatically. If you set this value, it only guides the algorithm to output the specified count when possible and does not guarantee that exact count. No default value. |
|
| No | 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. |
|
| No | A list of messages containing optional conversation context to improve recognition accuracy. ImportantContext helps improve recognition of domain-specific terms. For usage, see Context enhancement. You can include up to 5 messages of each context type: ImportantWhen you include context, arrange |
|
| No | Instant hotwords, passed as key-value pairs. Each key is the hotword text ( Valid weights are integers from 1 to 5, or 50. A higher weight from 1 to 5 makes the model more likely to output the hotword. A weight of 50 defines a super hotword and significantly improves recall. You can specify up to 50 super hotwords. If you also configure precompiled hotwords, the two sets are merged. If the merged set exceeds 2000 hotwords, 2000 are selected at random. For usage, see Instant hotwords. ImportantFor models and limits that apply to instant hotwords, see Instant hotwords. |
|
| No | The language codes to recognize. If you can't determine the language in advance, leave it unset and the model detects the language automatically. You can set up to 4 values. If you set more, only the first 4 take effect. Click to view the supported language codes
|
Key interfaces
NeoNui
nui_initialize
Initializes the speech recognition SDK instance. The SDK is a singleton. Do not initialize it again before you call nui_release.
-(NuiResultCode) nui_initialize:(const char *)parameters
logLevel:(NuiSdkLogLevel)level
saveLog:(BOOL)save_log;
Parameter descriptions
| Parameter | Type | Description |
|---|---|---|
|
| A JSON string that contains the authentication, connection, and debugging parameters. See Connection and control parameters. |
|
| Controls the print level of the SDK's own logs. |
|
| Whether to save logs locally. If set to |
nui_set_params
Use this interface to set or update the nls_config parameter independently. If you provide all parameters at once in nui_file_trans_start, you don't need to call this method.
-(NuiResultCode) nui_set_params:(const char *)params;
Parameter descriptions
| Parameter | Type | Description |
|---|---|---|
|
| The Example: |
nui_file_trans_start
Starts recognition.
Method signature-(NuiResultCode) nui_file_trans_start:(const char *)params
taskId:(char *)task_id;
Parameter descriptions
| Parameter | Type | Description |
|---|---|---|
|
| Speech recognition effect parameters. Example: |
|
| The task ID. The SDK generates a random string internally and returns the task_id when this interface is called successfully. |
nui_file_trans_query
Use this interface to actively query the current status and result of an asynchronous task. After a successful call, the result is returned through the EVENT_FILE_TRANS_QUERY_RESULT event in the onFileTransEventCallback callback.
NoteObtain the task_id passed to this method from the EVENT_FILE_TRANS_UPLOADED event.
-(NuiResultCode) nui_file_trans_query:(const char *)task_id;
Parameter descriptions
| Parameter | Type | Description |
|---|---|---|
|
| The ID of the task to query, obtained from the |
nui_file_trans_cancel
Cancels the current task immediately.
Method signature-(NuiResultCode) nui_file_trans_cancel:(const char *)task_id;
Parameter descriptions
| Parameter | Type | Description |
|---|---|---|
|
| The ID of the task to cancel, obtained from the |
nui_release
Releases all internal SDK resources and forcibly terminates all ongoing tasks. After you call this method, the SDK instance becomes unavailable. To use it again, you must call nui_initialize again to initialize it.
-(NuiResultCode) nui_release;
nui_get_version
Gets the current SDK version information.
Method signature-(const char*) nui_get_version;
Return value
The current SDK version information.
NeoNuiSdkDelegate: monitor callbacks
onFileTransEventCallback: monitor events and speech recognition results
Method signature-(void) onFileTransEventCallback:(NuiCallbackEvent)nuiEvent
asrResult:(const char *)asr_result
taskId:(const char *)task_id
ifFinish:(BOOL)finish
retCode:(int)code;
Parameter descriptions
| Parameter | Type | Description |
|---|---|---|
|
| The callback event. |
|
| The speech recognition result. |
|
| The task ID. |
|
| Indicates whether this round of recognition has finished. |
|
| Valid only when the |
onFileTransLogTrackCallback: monitor trace logs
Use this callback to receive detailed internal SDK logs for troubleshooting and debugging.
-(void)onFileTransLogTrackCallback:(NuiSdkLogLevel)level
logMessage:(const char *)log;
NuiCallbackEvent: event types
| Event | Description |
|---|---|
| Connected to the service successfully. |
| The audio file to recognize was uploaded successfully. You can now obtain the |
| The query task result. |
| The final recognition result. |
| An error occurred during speech recognition. |