This guide shows you how to convert speech to text with the Qwen-Audio-ASR-Filetrans non-real-time speech recognition Android SDK.
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. For better security, store the API key in an environment variable.
-
Download the SDK and run the sample code:
- Download the latest SDK package.
- Extract the ZIP package. Find the AAR-format SDK in the
app/libsdirectory and add it to your project dependencies. For Android C++ integration, useandroid_libsandandroid_includein the ZIP package to get the dynamic libraries and header files. - Open the project in Android Studio. The sample code is in
DashFunAsrFileTranscriberActivity.java. Replace the API key, then try out the feature.
Call procedure
Synchronous mode
- Initialize the SDK.
- Configure the parameters that your business requires.
- Set
async_requesttofalseand callstartFileTranscriberto submit a non-real-time speech recognition request and wait for the result. - Listen for the
EVENT_FILE_TRANS_RESULTevent in theonFileTransEventCallbackinterface to get the final recognition result. - Call
releaseto release the SDK resources.
Asynchronous mode
- Initialize the SDK.
- Configure the parameters that your business requires.
- Set
async_requesttotrueand callstartFileTranscriberto submit a non-real-time speech recognition request. - Call
queryFileTranscriberto poll for the recognition progress and result. - Listen for the
EVENT_FILE_TRANS_QUERY_RESULTevent in theonFileTransEventCallbackinterface to get the current query result. - Listen for the
EVENT_FILE_TRANS_RESULTevent in theonFileTransEventCallbackinterface to get the final recognition result. - Call
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 initialize interface.
Parameter example
The following JSON string is an example and does not list every parameter. Add the parameters 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 description
| 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 mainly used for log tracing and troubleshooting. |
|
| No | The storage path for the log file. This parameter takes effect only when At most two log files are kept locally. |
|
| No | The maximum size of the log file, in bytes. This parameter takes effect only when Default: 104857600 (100 * 1024 * 1024 bytes, that is, 100 MiB). |
|
| No | The filter level for the log content sent through the log callback ( Default: 2. Valid values:
Note: |
Speech recognition parameters
Configure all speech recognition parameters through the startFileTranscriber interface.
Parameter example
The following JSON string is an example and does not list every parameter. Add the parameters 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 description
| 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 recognition request is asynchronous. Default: Valid values:
|
|
| No | If the |
|
| Yes | The core configuration object for speech recognition. It contains key parameters such as model selection and recognition control. |
|
| 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: 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
NativeNui
initialize
Initializes the speech recognition SDK instance. The SDK is a singleton. Do not initialize it again before you call release.
This interface blocks, so call it on a non-UI thread.
Method signaturepublic synchronized int initialize(final INativeFileTransCallback callback,
String parameters,
final Constants.LogLevel level,
final boolean save_log)
Parameter description
| Parameter | Type | Description |
|---|---|---|
|
| The implementation of the event and data callback interface. |
|
| 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 |
setParams
Use this interface to set or update the nls_config parameters separately. If you provide all parameters at once in startFileTranscriber, you don't need to call this method.
public synchronized int setParams(String params);
Parameter description
| Parameter | Type | Description |
|---|---|---|
|
| The Example: |
startFileTranscriber
Starts recognition.
Method signaturepublic synchronized int startFileTranscriber(String params, byte[] task_id)
Parameter description
| Parameter | Type | Description |
|---|---|---|
|
| Speech recognition parameters. Example: |
|
| The task ID. The SDK generates a random string internally. You get the task_id after this interface returns successfully. |
queryFileTranscriber
Use this interface to query the current status and result of an asynchronous task. After the call succeeds, 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.
public synchronized int queryFileTranscriber(String task_id)
Parameter description
| Parameter | Type | Description |
|---|---|---|
|
| The ID of the task to query, obtained from the |
cancelFileTranscriber
Cancels the current task immediately.
Method signaturepublic synchronized int cancelFileTranscriber(String task_id)
Parameter description
| Parameter | Type | Description |
|---|---|---|
|
| The ID of the task to cancel, obtained from the |
release
Releases all internal resources of the SDK. After you call this method, the SDK instance becomes unusable. To use it again, you must call initialize to initialize it again.
public synchronized int release();
GetVersion
Gets the current SDK version information.
Method signaturepublic synchronized String GetVersion();
Return value
The current SDK version information.
INativeFileTransCallback: listener callbacks
onFileTransEventCallback: listen for events and recognition results
Method signaturevoid onFileTransEventCallback(NuiEvent event, final int resultCode, final int arg2, AsrResult asrResult, String taskId);
Parameter description
| Parameter | Type | Description |
|---|---|---|
|
| The callback event. |
|
| Valid only when the |
|
| The speech recognition result. |
|
| The task ID. |
|
| A reserved parameter. |
onFileTransLogTrackCallback: listen for trace logs
This callback receives the SDK's detailed internal logs for problem diagnosis and debugging.
default void onFileTransLogTrackCallback(Constants.LogLevel level, String log)
NuiEvent: event types
| Event | Description |
|---|---|
| The service connection succeeded. |
| The audio file to recognize was uploaded successfully. You can now obtain the |
| A task result query. |
| The final recognition result. |
| An error occurred during speech recognition. |