Qwen-Audio-3.0-ASR-Flash-Filetrans/Fun-ASR non-real-time speech recognition Android SDK

更新时间:
复制 MD 格式

This guide shows you how to convert speech to text with the Qwen-Audio-3.0-ASR-Flash-Filetrans/Fun-ASR non-real-time speech recognition Android SDK.

User guide:Non-real-time speech recognition. For input requirements such as supported audio formats, file size limits, and duration limits, see Audio specifications.

Quick start

  1. Get an API key: Obtain an API key. For better security, store the API key in an environment variable.

  2. 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/libs directory and add it to your project dependencies. For Android C++ integration, use android_libs and android_include in 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

  1. Initialize the SDK.

  2. Configure the parameters that your business requires.

  3. Call startFileTranscriber to start the recognition task (set async_request to false).

  4. Listen for the EVENT_FILE_TRANS_RESULT event in the onFileTransEventCallback interface to get the final recognition result.

  5. Call release to release the SDK resources.

Asynchronous mode

  1. Initialize the SDK.

  2. Configure the parameters that your business requires.

  3. Call startFileTranscriber to start the recognition task (set async_request to true).

  4. Call queryFileTranscriber to poll for the recognition progress and result.

  5. Listen for the EVENT_FILE_TRANS_QUERY_RESULT event in the onFileTransEventCallback interface to get the current query result.

  6. Listen for the EVENT_FILE_TRANS_RESULT event in the onFileTransEventCallback interface to get the final recognition result.

  7. Call 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 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-ws/v1/inference",
        "apikey": "st-****",
        "device_id": "my_device_id",
        "service_mode": "1"
    }
  • Parameter description

    Parameter

    Type

    Required

    Description

    url

    String

    Yes

    The service endpoint. Fixed to wss://dashscope.aliyuncs.com/api-ws/v1/inference.

    apikey

    String

    Yes

    The API key.

    service_mode

    String

    Yes

    The run mode. Fixed to "1" for recorded speech recognition.

    device_id

    String

    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.

    debug_path

    String

    No

    The storage path for the log file.

    This parameter takes effect only when save_log is set to true in the initialize interface. In that case, you must set the log file path, or an error is reported.

    At most two log files are kept locally.

    max_log_file_size

    int

    No

    The maximum size of the log file, in bytes.

    This parameter takes effect only when save_log is set to true in the initialize interface.

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

    log_track_level

    int

    No

    The filter level for the log content sent through the log 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 (turns off this feature)

    Note: log_track_level and level (set through the initialize interface) 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), only logs at WARNING level or higher (value >= 3) are sent to the callback.

Speech recognition parameters

Configure the nl_config parameter through the setParams interface, or 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:

    {
        "file_urls": [
            "{YOUR_AUDIO_URL}"
        ],
        "async_request": false,
        "nls_config": {
            "model":"qwen-audio-3.0-asr-flash-filetrans",
            "diarization_enabled": false,
            "parameters": {
                "speech_noise_threshold": 0.0
            }
        }
    }
  • Parameter description

    Parameter

    Type

    Required

    Description

    file_urls

    array[string]

    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 oss://, whereas the SDK does not support oss://-prefixed temporary URLs.

    Important
    • A temporary URL is valid for 48 hours and cannot be used after it expires. Do not use it in production.

    • The upload credential interface is rate-limited to 100 QPS and cannot be scaled up. Do not use it in production, high-concurrency, or load-testing scenarios.

    • For production, use stable storage such as Alibaba Cloud OSS to keep files available long-term and avoid rate limiting.

    • If an audio file URL set to an OSS temporary public URL is unreachable, set X-DashScope-OssResourceResolve to enable in the request header (not recommended).

      The SDK does not support configuring request headers.

    async_request

    boolean

    No

    Whether the recognition request is asynchronous.

    Default: false.

    Valid values:

    • true: asynchronous request

    • false: synchronous request

    apikey

    string

    No

    If the apikey in Connection and control parameters is a temporary API key, you can update it here to avoid expiration.

    nls_config

    object

    Yes

    The core configuration object for speech recognition. It contains key parameters such as model selection and recognition control.

    nls_config.model

    string

    Yes

    The model name. Supported values include the Qwen-Audio-3.0-ASR-Flash-Filetrans and Fun-ASR model families. For details, see Supported models and regions.

    nls_config.special_word_filter

    object

    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.

    nls_config.channel_id

    array[integer]

    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.

    Important

    Each specified track is billed independently. For example, requesting [0, 1] for a single file incurs two separate charges.

    Default value: [0].

    nls_config.diarization_enabled

    boolean

    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 speaker_id field that distinguishes different speakers.

    Note

    When speaker diarization is enabled, keep the audio duration within 2 hours. Otherwise, recognition may fail or time out.

    Default: false.

    For an example of speaker_id, see Recognition result description.

    nls_config.speaker_count

    integer

    No

    Important

    Takes effect only when speaker diarization is enabled (diarization_enabled is set to true).

    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.

    nls_config.vocabulary_id

    string

    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.

    nls_config.language_hints

    array[string]

    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.

    For Qwen-Audio-3.0-ASR-Flash-Filetrans models, you can set up to 4 values; any values beyond the first 4 are ignored. For Fun-ASR models, you can set only 1 value; if you set multiple, only the first takes effect.

    Click to view the supported language codes

    • qwen-audio-3.0-asr-flash-filetrans, fun-asr, fun-asr-2025-11-07, fun-asr-mtl, fun-asr-mtl-2025-08-25:

      • zh: Chinese

      • en: English

      • ja: Japanese

      • ko: Korean

      • vi: Vietnamese

      • th: Thai

      • id: Indonesian

      • ms: Malay

      • tl: Filipino

      • hi: Hindi

      • ar: Arabic

      • fr: French

      • de: German

      • es: Spanish

      • pt: Portuguese

      • ru: Russian

      • it: Italian

      • nl: Dutch

      • sv: Swedish

      • da: Danish

      • fi: Finnish

      • no: Norwegian

      • el: Greek

      • pl: Polish

      • cs: Czech

      • hu: Hungarian

      • ro: Romanian

      • bg: Bulgarian

      • hr: Croatian

      • sk: Slovak

    • fun-asr-2025-08-25:

      • zh: Chinese

      • en: English

    nls_config.parameters

    object

    No

    Other parameters, in JSON Object format.

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 signature

    public synchronized int initialize(final INativeFileTransCallback callback,
                                       String parameters,
                                       final Constants.LogLevel level,
                                       final boolean save_log)
  • Parameter description

    Parameter

    Type

    Description

    callback

    INativeFileTransCallback

    The implementation of the event and data callback interface.

    parameters

    String

    A JSON string that contains the authentication, connection, and debugging parameters. See Connection and control parameters.

    level

    Constants.LogLevel

    Controls the print level of the SDK's own logs.

    save_log

    boolean

    Whether to save logs locally. If true, specify the 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.

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.

  • Method signature

    public synchronized int setParams(String params);
  • Parameter description

    Parameter

    Type

    Description

    params

    String

    The nls_config parameter in Speech recognition parameters. Parameters other than nls_config cannot be set through this method.

    Example:

    {
        "nls_config": {
            "model":"qwen-audio-3.0-asr-flash-filetrans",
            "diarization_enabled": false
        }
    }
  • Return value

    Returns an error code. See Error code reference.

startFileTranscriber

Starts recognition.

  • Method signature

    public synchronized int startFileTranscriber(String params, byte[] task_id)
  • Parameter description

    Parameter

    Type

    Description

    params

    String

    Speech recognition parameters.

    Example:

    {
        "file_urls": [
            "{YOUR_AUDIO_URL}"
        ],
        "async_request": false,
        "nls_config": {
            "model":"qwen-audio-3.0-asr-flash-filetrans",
            "diarization_enabled": false
        }
    }

    task_id

    byte[]

    The task ID. The SDK generates a random string internally. You get the task_id after this interface returns successfully.

  • Return value

    Returns an error code. See Error code reference.

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.

  • Method signature

    public synchronized int queryFileTranscriber(String task_id)
  • Parameter description

    Parameter

    Type

    Description

    task_id

    byte[]

    The ID of the task to query.

  • Return value

    Returns an error code. See Error code reference.

cancelFileTranscriber

Cancels the current task immediately.

  • Method signature

    public synchronized int cancelFileTranscriber(String task_id)
  • Parameter description

    Parameter

    Type

    Description

    task_id

    byte[]

    The ID of the task to cancel.

  • Return value

    Returns an error code. See Error code reference.

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.

  • Method signature

    public synchronized int release();
  • Return value

    Returns an error code. See Error code reference.

GetVersion

Gets the current SDK version information.

  • Method signature

    public synchronized String GetVersion();
  • Return value

    The current SDK version information.

INativeFileTransCallback: listener callbacks

onFileTransEventCallback: listen for events and recognition results

  • Method signature

    void onFileTransEventCallback(NuiEvent event, final int resultCode, final int arg2, AsrResult asrResult, String taskId);
  • Parameter description

    Parameter

    Type

    Description

    event

    NuiEvent

    The callback event.

    resultCode

    int

    The error code. Valid when the EVENT_ASR_ERROR event occurs.

    asrResult

    AsrResult

    The speech recognition result.

    taskId

    String

    The task ID.

    arg2

    int

    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

EVENT_FILE_TRANS_CONNECTED

The service connection succeeded.

EVENT_FILE_TRANS_UPLOADED

The audio file to recognize was uploaded successfully.

EVENT_FILE_TRANS_QUERY_RESULT

A task result query.

EVENT_FILE_TRANS_RESULT

The final recognition result.

EVENT_ASR_ERROR

An error occurred during speech recognition.