Use the Flutter SDK for Qwen-Livetranslate-Realtime real-time audio and video translation, including the Dart call sequence, request parameters, and events.
Qwen-Livetranslate-Realtime takes real-time audio and outputs translations. Your app can receive translated text, or both translated text and speech.
Download the mobile speech SDK package from SDK downloads. After extracting it, copy the Flutter SDK directory into
Run
Get an instance with
The following example uses the model included in the package. For other fields, see
The following example uses Singapore. For another region, replace
Pass this JSON as a string to the Dart methods.
The
For methods that return
Read events from
Prerequisites
- Set up Flutter development for your target platform. The example project requires Dart 3.4 or later, below 4.0.
- Obtain an API key.
Install the SDK
Download the mobile speech SDK package from SDK downloads. After extracting it, copy the Flutter SDK directory into packages/aliyun_neonui in your project and add a local dependency in pubspec.yaml.
flutter pub get, then import the SDK in your Dart files.
Quick start
- Connect your target device and run the example from the extracted SDK directory.
- Open the example app, select a service endpoint, and enter your API key.
- Open the Qwen-LiveTranslate real-time audio and video translation example and run it. Allow microphone access when prompted.
example/lib/pages/dashscope/dash_live_translate_page.dart in the package.
The package includes the qwen3.5-livetranslate-flash-realtime model.
Call sequence
Get an instance with NativeNui() and call the following methods. initJson and sessionJson correspond to the connection parameters and task parameters in Request parameters. Call each method only after the previous one succeeds.
- Subscribe to
eventStreamandttsAudioStreamfirst, then initialize the SDK and start the session.
- After the session starts, capture audio and send PCM data continuously with
sendAudio. The package's recording example captures 16 kHz, 16-bit, mono PCM.
- After you stop capturing, call
dialogStop. After handling the last events, callnuiReleaseand cancel the subscriptions.
Request parameters
The following example uses the model included in the package. For other fields, see example/lib/dashscope_params.dart in the package. For more parameter details, see the WebSocket integration guide.
Connection parameters
The following example uses Singapore. For another region, replace ap-southeast-1 with the region ID. See Regions and endpoints. Pass this JSON as a string to the Dart methods.
Task parameters
Pass this JSON as a string to the Dart methods.
model query parameter in the URL sets the translation model. nls_config.model sets an optional speech recognition model. translation is a JSON string that contains the target language. You can omit source_language to detect the source language automatically.
API reference
Methods
For methods that return Future<int>, a result code of 0 indicates success. sendAudio returns Future<Object?>.
| Method signature | Purpose |
|---|---|
Future<int> nuiInitialize({required String params, int logLevel = 0, bool saveLog = false}) | Initialize the SDK. params is the connection parameters 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 sets the endpointing mode, and dialogParams can pass JSON parameters for this session. |
Future<Object?> sendAudio(Uint8List data) | Send a chunk of PCM audio. |
Future<int> dialogStop() | Stop the current capture session and keep the connection. |
Future<int> dialogCancel() | Cancel the current session or synthesis. |
Future<int> nuiRelease() | Release SDK resources. |
Events and audio streams
Read events from eventStream. For Dart Map events, use event to identify the event name, and use resultCode on task events to check for errors.
The ttsAudioStream audio stream returns audio chunks. Your app is responsible for playback.
| Event | Purpose |
|---|---|
EVENT_ASR_PARTIAL_RESULT | Interim recognition result |
EVENT_RESULT_TRANSLATED | Translation result |
EVENT_RESULT_TRANSLATED_END | Final translation result for the current sentence |
EVENT_TRANSCRIBER_COMPLETE | Task or current audio output completed |
EVENT_ASR_ERROR | Task failed |