Integrate Qwen-Audio-Realtime with the Flutter SDK. See the Dart call sequence, request parameters, and events.
Qwen-Audio-Realtime takes live audio and returns model responses. Configure the session to receive response text and audio.
Open Mobile speech SDK selection and download, select Flutter, and download and extract the package.
Copy the extracted SDK directory to
Run
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.
Use the same model ID in the URL query parameter
For methods returning
Read events from
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 实时语音对话 and run the example. Allow microphone access when running an audio capture example.
example/lib/pages/dashscope/dash_qwen_audio_chat_page.dart in the SDK package.
Models in the included example
qwen-audio-3.1-realtime-plusqwen-audio-3.0-realtime-plusqwen-audio-3.0-realtime-flash
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
eventStreamandttsAudioStreambefore 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. The included recording example captures 16 kHz, 16-bit, mono PCM. On iOS, start the microphone before starting the audio player. If the player is already running, restart it after the microphone starts so the response audio can play. -
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.
model and in nls_config.model. For this Dart SDK, modalities and turn_detection are JSON strings.
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<int> dialogAction(String actionParams) | Send a tool-call result to the session. |
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.
The ttsAudioStream stream emits audio chunks for the app to play.
| Event | Purpose |
|---|---|
EVENT_ASR_PARTIAL_RESULT | Partial recognition result |
EVENT_SENTENCE_END | Final recognition result for the current sentence |
EVENT_AUDIO_TRANSCRIPTION_COMPLETED | Transcription of the spoken response complete |
EVENT_ASR_TTS_START | Synthesis or response audio started |
EVENT_ASR_TTS_COMPLETE | Task or current audio output complete |
EVENT_ASR_ERROR | Task failed |