All Products
Search
Document Center

Alibaba Cloud Model Studio:Qwen-Audio-TTS / CosyVoice Flutter SDK

Last Updated:Nov 19, 2026

Integrate Qwen-Audio-TTS / CosyVoice with the Flutter SDK. See the Dart call sequence, request parameters, and events.

Qwen-Audio-TTS and CosyVoice share bidirectional streaming APIs. Your app can send text in chunks while receiving synthesized audio.

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.

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

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.

dependencies:
  aliyun_neonui:
    path: packages/aliyun_neonui

Run flutter pub get, then import the SDK in your Dart file.

import 'package:aliyun_neonui/neonui.dart';

Quick start

Run the example app

  1. Connect your target device. Run these commands from the extracted SDK directory.

    cd example
    flutter pub get
    flutter run
    
  2. 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.

  3. Open Qwen-Audio-TTS/CosyVoice 双向流式语音合成 and run the example.

The complete example is in example/lib/pages/dashscope/dash_cosy_voice_stream_tts_page.dart in the SDK package.

Models in the included example

  • qwen-audio-3.1-tts-flash
  • qwen-audio-3.1-tts-plus
  • qwen-audio-3.0-tts-flash
  • qwen-audio-3.0-tts-plus
  • cosyvoice-v3-flash
  • cosyvoice-v3-plus

Call procedure

Call these methods on the instance returned by NativeNui().

  1. Subscribe to streamTtsEventStream and streamTtsAudioStream before calling these methods.

  2. Use the connection JSON and task JSON below as ticketJson and paramsJson.

    await nui.streamTtsStart(ticket: ticketJson, params: paramsJson);
    await nui.streamTtsSend('你好,');
    await nui.streamTtsSend('欢迎使用语音合成。');
    

    After starting synthesis, send text in chunks and play the audio received from the stream.

  3. End text input with streamTtsStop. After the synthesis completion event, call streamTtsRelease.

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 connection JSON as ticket.

{
  "apikey": "YOUR_API_KEY",
  "device_id": "YOUR_DEVICE_ID",
  "url": "wss://YOUR_WS_HOST/api-ws/v1/inference"
}

Task parameters

Pass the example JSON as a string to the Dart method.

{
  "model": "qwen-audio-3.1-tts-flash",
  "voice": "longanhuan_v3.1",
  "format": "pcm",
  "enable_audio_decoder": false,
  "sample_rate": 24000,
  "volume": 50,
  "rate": 1.0,
  "pitch": 1.0
}

Use a voice compatible with the model. format and sample_rate set the output format and sample rate. The example enables enable_audio_decoder for MP3 or Opus.

API reference

Methods

For methods returning Future<int>, result code 0 indicates success.

Method signaturePurpose
Future<int> streamTtsStart({required String ticket, required String params, String sessionId = "", int logLevel = 0, bool saveLog = false})Create a streaming synthesis session. Pass ticket and params as two JSON strings.
Future<int> streamTtsSend(String text)Send the next text chunk.
Future<int> streamTtsStop({bool flagAsync = true})End text input. flagAsync defaults to true for asynchronous stopping.
Future<int> streamTtsAsyncPlay({required String ticket, required String params, required String text, String sessionId = "", int logLevel = 0, bool saveLog = false})Submit the full text in one call and receive synthesis results asynchronously.
Future<int> streamTtsCancel()Cancel the current session or synthesis task.
Future<int> streamTtsRelease()Release SDK resources.

Events and audio streams

Read events from streamTtsEventStream. For events delivered as Dart maps, read the event name from event and use resultCode to inspect task errors.

The streamTtsAudioStream stream emits audio chunks for the app to play.

EventPurpose
STREAM_INPUT_TTS_EVENT_SYNTHESIS_STARTEDSynthesis or response audio started
STREAM_INPUT_TTS_EVENT_SENTENCE_SYNTHESISSentence-level synthesis event
STREAM_INPUT_TTS_EVENT_SYNTHESIS_COMPLETETask or current audio output complete
STREAM_INPUT_TTS_EVENT_TASK_FAILEDTask failed