Skip to main content
SDK access

Qwen-Livetranslate-Realtime Flutter SDK

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.

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.
Do not hardcode a long-lived API key in a mobile app. For models that accept temporary API keys, have your application server generate a temporary API key and send it to the client.

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.
dependencies:
  aliyun_neonui:
    path: packages/aliyun_neonui
Run flutter pub get, then import the SDK in your Dart files.
import 'package:aliyun_neonui/neonui.dart';

Quick start

  1. Connect your target device and run the example from the extracted SDK directory.
cd example
flutter pub get
flutter run
  1. Open the example app, select a service endpoint, and enter your API key.
  2. Open the Qwen-LiveTranslate real-time audio and video translation example and run it. Allow microphone access when prompted.
The complete example is in 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.
  1. Subscribe to eventStream and ttsAudioStream first, then initialize the SDK and start the session.
await nui.nuiInitialize(params: initJson);
await nui.dialogSetParams(sessionJson);
await nui.dialogStart(vadMode: VadMode.p2t.code, dialogParams: sessionJson);
  1. 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.
On iOS, start the microphone before the player. If the player is already running, restart it after the microphone starts to avoid silent reply audio.
  1. After you stop capturing, call dialogStop. After handling the last events, call nuiRelease and 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.
{
  "device_id": "YOUR_DEVICE_ID",
  "url": "wss://ap-southeast-1.maas.qwencloudapi.com/api-ws/v1/realtime?model=qwen3.5-livetranslate-flash-realtime",
  "service_mode": "1",
  "audio_update_manually": "false"
}

Task parameters

Pass this JSON as a string to the Dart methods.
{
  "apikey": "YOUR_API_KEY",
  "nls_config": {
    "sample_rate": 16000,
    "sr_format": "pcm",
    "modalities": "[\"text\",\"audio\"]",
    "source_language": "zh",
    "translation": "{\"language\":\"en\"}",
    "turn_detection": "{\"type\":\"server_vad\",\"threshold\":0.2,\"silence_duration_ms\":1000}"
  },
  "service_type": 4
}
The 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 signaturePurpose
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.
EventPurpose
EVENT_ASR_PARTIAL_RESULTInterim recognition result
EVENT_RESULT_TRANSLATEDTranslation result
EVENT_RESULT_TRANSLATED_ENDFinal translation result for the current sentence
EVENT_TRANSCRIBER_COMPLETETask or current audio output completed
EVENT_ASR_ERRORTask failed