Qwen-Audio-3.x-ASR-Flash/Fun-ASR-Flash non-real-time speech recognition Android 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.
Pass a JSON string to the initialize method's
Parameters
Use startFileTranscriber 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:
Parameters
messages parameters:
content parameters:
Initialize the speech recognition SDK instance. The SDK uses a singleton. Do not initialize it again before calling release.
This method blocks. Call it from a non-UI thread.
Method signature
Parameters
Use this method to set or update
Parameters
Start recognition.
Method signature
Parameters
This non-real-time speech recognition feature only supports synchronous requests. You can ignore this method.
Immediately cancel the current task.
Method signature
Parameters
Release all internal SDK resources. After this call, the SDK instance becomes unavailable. To use it again, call initialize to initialize it again.
Method signature
Get the current SDK version.
Method signature
Return value
The current SDK version.
Method signature
Parameters
This callback receives detailed internal SDK logs for troubleshooting and debugging.
Quick start
- Get an API key: Get an API key. For security, we recommend that you configure the API key in an environment variable.
- Download the SDK and run the sample code:
- Download the latest SDK bundle.
- Extract the ZIP archive. Obtain the SDK in AAR format from
app/libsand add it to your project dependencies. For Android CPP integration, useandroid_libsandandroid_includein the ZIP archive to obtain the dynamic libraries and header files. - Open the project in Android Studio. The sample code is in
DashFunAsrFlashFileTranscriberActivity.java. Replace the API key to try the feature.
Call procedure
Synchronous mode
- Initialize the SDK
- Configure the parameters based on your business requirements
-
Call
startFileTranscriberto send a non-real-time speech recognition request and wait for the result. -
Use
onFileTransEventCallbackto listen for theEVENT_FILE_TRANS_RESULTevent and obtain the final recognition result. -
Call
releaseto release SDK resources
Request parameters
Connection and control parameters
Pass a JSON string to the 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:
| 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 "1". |
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 initialize with save_log set to true. In this case, you must specify the log file path. Otherwise, an error occurs. Up to two log files are retained locally. |
max_log_file_size | int | No | The maximum log file size in bytes. This parameter takes effect only when you call initialize with save_log set to true. Default: 104857600 (100 * 1024 * 1024 bytes, or 100 MiB). |
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: log_track_level and level (configured through initialize method) jointly determine which logs are delivered. The numeric level of a log must be greater than or equal to both log_track_level and level for the log to be delivered. For example, if log_track_level is set to 2 (INFO) and level is set to 3 (WARNING), only WARNING and higher-severity logs (numeric level >= 3) are delivered. |
Recognition parameters
Use startFileTranscriber 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
apikey | string | No | If Connection and control parameters apikey uses temporary API key, you can update it here to prevent expiration. |
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 used in the example. For model information, see Supported models and regions. |
nls_config.format | string | Yes | The audio format. Set this parameter to the actual format. Supported formats include wav, mp3, opus. For details, see Audio specifications. |
nls_config.sample_rate | string | No | The audio sample rate in Hz. For example, 16000 indicates a sample rate of 16 kHz. For details, see Audio specifications. |
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. Pass key-value pairs. The key is the hotword text ( string) and the value is its weight (integer). You do not need to create a vocabulary in advance. Valid weights are [1, 5] or 50. Within [1, 5], a higher weight makes the model more likely to output the word. A weight of 50 specifies a super hotword and significantly increases recall. You can specify up to 50 super hotwords.Use this option for temporary, session-level hotword optimization. When both instant and precompiled hotwords are configured, the system merges them. If the merged list exceeds 2000 entries, it randomly selects 2000 entries. For usage instructions, see Instant hotwords. |
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. For Qwen-Audio-3.0-ASR-Flash models, up to four values are supported. If more are specified, only the first four take effect. For Fun-ASR-Flash models, only one value is supported. If multiple values are specified, only the first takes effect.
|
| messages | array[object] | Yes | The list of messages. It contains the audio to recognize and optional conversation context to improve recognition. See the following descriptions. |
| 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 message. Valid values:
|
| input_audio | object | No | Required when type is input_audio. |
| 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 type is input_text, provide recognition results of user speech from previous turns or a domain-specific vocabulary. When type is text, provide large language model responses from previous turns. Text length is counted in characters, with each character counting as one. The total length of all messages' text fields in each context turn must not exceed 400 characters. Excess characters are truncated from the end. |
Key interfaces
NativeNui
initialize
Initialize the speech recognition SDK instance. The SDK uses a singleton. Do not initialize it again before calling release.
This method blocks. Call it from a non-UI thread.
Method signature
| Parameter | Type | Description |
|---|---|---|
callback | INativeFileTransCallback | The implementation of the event and data callback interface. |
parameters | String | A JSON string containing authentication, connection, and debugging parameters. See Connection and control parameters. |
level | Constants.LogLevel | The level of logs printed by the SDK. |
save_log | boolean | Whether to save logs locally. If set to true, use Connection and control parameters to set debug_path to specify the path, and use max_log_file_size to set the file size. |
setParams
Use this method to set or update nls_config separately. You do not need to call this method if all parameters are provided in startFileTranscriber in a single call.
Method signature
| Parameter | Type | Description |
|---|---|---|
params | String | Recognition parameters in nls_config and messages parameters.Example: |
startFileTranscriber
Start recognition.
Method signature
| Parameter | Type | Description |
|---|---|---|
params | String | Recognition parameters. Example: |
task_id | byte[ ] | You can ignore this parameter and pass null. |
queryFileTranscriber
This non-real-time speech recognition feature only supports synchronous requests. You can ignore this method.
cancelFileTranscriber
Immediately cancel the current task.
Method signature
| Parameter | Type | Description |
|---|---|---|
task_id | String | The ID of the task to cancel, obtained from EVENT_FILE_TRANS_UPLOADED. |
release
Release all internal SDK resources. After this call, the SDK instance becomes unavailable. To use it again, call initialize to initialize it again.
Method signature
GetVersion
Get the current SDK version.
Method signature
INativeFileTransCallback: Callbacks
onFileTransEventCallback: Listen for events and recognition results
Method signature
| Parameter | Type | Description |
|---|---|---|
event | NuiEvent | The callback event. |
resultCode | int | Valid only when the EVENT_ASR_ERROR event occurs. |
asrResult | AsrResult | The speech recognition result. |
taskId | String | The task ID. |
arg2 | int | Reserved. |
onFileTransLogTrackCallback: Listen for tracing logs
This callback receives detailed internal SDK logs for troubleshooting and debugging.
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. |