Integrate Qwen-Audio-ASR / Fun-ASR with the Flutter SDK. See the Dart call sequence, request parameters, and events.
Real-time recognition transcribes speech. Qwen-Audio-ASR-Message, Qwen-Audio-ASR-Streaming, and Fun-ASR share the same session and microphone APIs. Use
Open Mobile speech SDK selection and download, select Flutter, and download and extract the package.
Copy the extracted SDK directory to
Run
The included example records audio at 16 kHz. Choose a model that accepts 16 kHz audio to run the example as provided. To use
Call these methods on the instance returned by
The following example uses a model from the package. For additional settings, see
Pass the example JSON as a string to the Dart method.
Pass the example JSON as a string to the Dart method.
Set
For methods returning
Read events from
nls_config.model to select a model.
Prerequisites
- Set up Flutter development for your target platform. The example app requires Dart 3.4 or later, below 4.0.
- Get an API key. Choose a service endpoint in the same region as the API key. If you use a workspace-specific domain, also get your workspace ID.
Install the SDK
Open Mobile speech SDK selection and download, select Flutter, and download and extract the package.
Copy the extracted SDK directory to packages/aliyun_neonui in your Flutter project and add the local dependency to pubspec.yaml.
flutter pub get, then import the SDK in your Dart file.
Quick start
Run the example app
-
Connect your target device. Run these commands from the extracted SDK directory.
- In the example app, open 百炼(DashScope) from the home screen. Select a service endpoint and enter your API Key. If you use a workspace-specific domain, enter your WorkspaceId as well.
- Open Qwen-Audio-3.x-ASR-Flash-Message/Qwen-Audio-3.x-ASR-Flash-Streaming/Fun-ASR-Realtime 实时语音识别 and run the example. Allow microphone access when running an audio capture example.
example/lib/pages/dashscope/dash_fun_asr_speech_transcriber_page.dart in the SDK package.
Models in the included example
The included example records audio at 16 kHz. Choose a model that accepts 16 kHz audio to run the example as provided. To use fun-asr-flash-8k-realtime, set the recording sample rate in example/lib/audio_input.dart to 8 kHz and set nls_config.sample_rate to 8000 in the request.
qwen-audio-3.1-asr-flash-messageqwen-audio-3.1-asr-flash-streamingqwen-audio-3.0-asr-flash-streamingfun-asr-realtimefun-asr-flash-8k-realtime
Call procedure
Call these methods on the instance returned by NativeNui().
Use the connection JSON and task JSON under Request parameters as initJson and sessionJson. Check the result of each call before continuing.
-
Subscribe to
eventStreambefore calling these methods. -
Set the connection and task parameters, then start the session.
-
Once the session starts, capture audio and send PCM chunks with
sendAudio. -
Stop capturing audio and call
dialogStop. After handling the last events, callnuiReleaseand cancel your subscriptions.
Request parameters
The following example uses a model from the package. For additional settings, see example/lib/dashscope_params.dart in the package. For additional parameter details, see Android SDK, iOS SDK, HarmonyOS SDK.
Replace YOUR_WS_HOST with the WebSocket host for your region, YOUR_DEVICE_ID with a device identifier, and YOUR_API_KEY with an API key for that region.
Connection parameters
Pass the example JSON as a string to the Dart method.
Task parameters
Pass the example JSON as a string to the Dart method.
nls_config.sample_rate and nls_config.sr_format to match your input audio. This example uses 16 kHz PCM. Configure options such as vocabulary and context according to the model documentation.
API reference
Methods
For methods returning Future<int>, result code 0 indicates success. The return type of sendAudio is Future<Object?>.
| Method signature | Purpose |
|---|---|
Future<int> nuiInitialize({required String params, int logLevel = 0, bool saveLog = false}) | Initialize the SDK with connection parameters as a JSON string. |
Future<int> dialogSetParams(String params) | Set the JSON parameters for the current session. |
Future<int> dialogStart({required int vadMode, String dialogParams = "{}"}) | Start the session. vadMode selects the segmentation mode, and dialogParams accepts a JSON string with per-session parameters. |
Future<Object?> sendAudio(Uint8List data) | Send a chunk of PCM audio. |
Future<int> dialogStop() | End the current capture session and keep the connection open. |
Future<int> dialogCancel() | Cancel the current session or synthesis task. |
Future<int> nuiRelease() | Release SDK resources. |
Future<String?> getAllResponse() | Read the latest full recognition response. |
Events and audio streams
Read events from eventStream. For events delivered as Dart maps, read the event name from event and use resultCode to inspect task errors.
See the example's handling of asrResult and asrAllResponse when reading recognition results.
| Event | Purpose |
|---|---|
EVENT_ASR_PARTIAL_RESULT | Partial recognition result |
EVENT_SENTENCE_END | Final recognition result for the current sentence |
EVENT_TRANSCRIBER_COMPLETE | Task or current audio output complete |
EVENT_ASR_ERROR | Task failed |