Skip to content
All packages

// Package

flutter_azure_tts

Microsoft Azure Text-to-Speech for Flutter. Turn text into audio as a complete file or as a real-time stream, with voice filtering, caching and retries built in.

likes
35
pub points
140/160
downloads in 30 days
295

Platforms

  • Android
  • iOS
  • Web
  • macOS
  • Windows
  • Linux

What it does

flutter_azure_tts connects a Flutter app to the Microsoft Azure Text-to-Speech API. You give it text and a voice. It returns audio, either as one complete file or as a stream of chunks you can play while the rest is still arriving.

Features

  • Standard TTS: generate a complete audio file from text.
  • Streaming TTS: receive audio in chunks for lower latency, with optional progress tracking.
  • Voice filtering: a chainable API to find voices by locale, gender, style or name.
  • Typed errors: a specific exception for each kind of failure, such as network, authentication, validation and rate limiting.
  • Caching: voices and audio are cached to avoid repeat requests.
  • Retries: a configurable retry policy with exponential backoff.
  • Builders: fluent builders that validate the parameters of each request.

Install

dependencies:
  flutter_azure_tts: ^1.0.0

Use it

Initialise the package once with your Azure subscription key and region:

FlutterAzureTts.init(
  subscriptionKey: 'YOUR_SUBSCRIPTION_KEY',
  region: 'YOUR_REGION',
  withLogs: true,
);

Pick a voice with the filtering API:

final voicesResponse = await FlutterAzureTts.getAvailableVoices();

final voice = voicesResponse.voices
    .filter()
    .byLocale('en-US')
    .neural()
    .firstOrThrow;

Turn text into audio:

final params = TtsParamsBuilder()
    .voice(voice)
    .text('Hello! This is Azure Text-to-Speech.')
    .audioFormat(AudioOutputFormat.audio16khz32kBitrateMonoMp3)
    .build();

final audioResponse = await FlutterAzureTts.getTts(params);
final audioBytes = audioResponse.audio;

Or stream it while it is being generated:

final streamingParams = TtsStreamingParamsBuilder()
    .voice(voice)
    .text('This audio will stream in real time.')
    .audioFormat(AudioOutputFormat.audio16khz32kBitrateMonoMp3)
    .build();

final response = await FlutterAzureTts.getTtsStream(streamingParams);

await for (final chunk in response.audioStream) {
  // Hand chunk.data to your audio player.
}

The full API, including voice styles and roles, is documented on pub.dev.