supertonic_flutter 2.1.0
supertonic_flutter: ^2.1.0 copied to clipboard
High-quality multilingual text-to-speech engine for Flutter. Supports 31 languages with multiple voice styles. Powered by Supertonic 3.
Supertonic TTS Flutter #
Multilingual text-to-speech (TTS) for Flutter. Powered by ONNX Runtime for fast local inference.
Note: This is an unofficial Flutter port of the Supertonic project.
v2.0.0 β Supertonic 3: Upgraded to Supertonic 3 (5 β 31 languages). This is a breaking change: the model cache is versioned, so apps re-download the new ~400 MB assets on first run. The old Supertonic 2 cache is left untouched.
Features #
- π Multilingual Support - 31 languages (English, Korean, Japanese, Spanish, Portuguese, French, German, and 24 more), plus a language-agnostic mode (
na) for unknown-language input - π Expression Tags - Supertonic 3 inline tags such as
<laugh>,<breath>, and<sigh>add natural, human-sounding nuance - π Multiple Voice Styles - 10 voices (5 male, 5 female)
- β‘ Local Processing - Runs fully on-device
- ποΈ Customizable - Adjustable speech speed and quality settings
- π± Cross-Platform - Supports Android, iOS, macOS, Linux, and Web
- π Neural TTS - Based on diffusion models
Platform Support #
| Platform | Status | Minimum Version |
|---|---|---|
| Android | β Supported | API 21+ (Android 5.0) |
| iOS | β Supported | iOS 16.0+ |
| macOS | β Supported | macOS 14.0+ |
| Linux | β Supported | Ubuntu 20.04+ |
| Web | β Supported | Modern browsers |
Web Setup #
For Web builds, flutter_onnxruntime requires ONNX Runtime Web to be loaded in
your app's web/index.html before flutter_bootstrap.js:
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/ort.min.js"></script>
<script src="flutter_bootstrap.js" async></script>
Installation #
Add this to pubspec.yaml:
dependencies:
supertonic_flutter: ^2.1.0
Quick Start #
import 'package:supertonic_flutter/supertonic_flutter.dart';
final tts = SupertonicTTS();
await tts.initialize();
final result = await tts.synthesize(
'Hello, world!',
language: 'en',
voiceStyle: 'M1',
);
initialize() uses this order:
- cached models
- bundled assets
- download from Hugging Face if needed
Expression Tags #
Add natural, human-sounding nuance with simple inline tags such as <laugh>, <breath>, and <sigh> β they are passed straight through to the model:
final result = await tts.synthesize(
'Well <laugh> that was unexpected!',
language: 'en',
voiceStyle: 'F2',
);
Language-Agnostic Mode #
Not sure which language your text is in? Pass language: 'na' and Supertonic handles the input in a language-agnostic way:
final result = await tts.synthesize(
'Bonjour and μλ
νμΈμ!',
language: 'na',
voiceStyle: 'M1',
);
Model Setup #
Option A: Auto-Download (Recommended) #
No manual setup required. Models are downloaded from Hugging Face on first use (~400 MB).
// Just initialize β models download automatically if not found
final tts = SupertonicTTS();
await tts.initialize();
To pre-download at a convenient time:
if (!await SupertonicTTS.modelsReady()) {
await SupertonicTTS.preDownloadModels(
onProgress: (done, total, file, progress) {
print('[$done/$total] $file: ${(progress * 100).toInt()}%');
},
);
}
Option B: Bundle Assets Manually #
Download the model files from Hugging Face and add them to your app's assets. This avoids runtime downloads but increases app size by ~400 MB.
assets/
βββ onnx/
β βββ duration_predictor.onnx
β βββ text_encoder.onnx
β βββ vector_estimator.onnx
β βββ vocoder.onnx
β βββ tts.json
β βββ unicode_indexer.json
βββ voice_styles/
βββ M1.json, M2.json, M3.json, M4.json, M5.json
βββ F1.json, F2.json, F3.json, F4.json, F5.json
Update pubspec.yaml:
flutter:
assets:
- assets/onnx/
- assets/voice_styles/
Platform Configuration #
This package uses flutter_onnxruntime, which needs a few platform-specific settings:
β‘οΈ Android
Add a ProGuard rule so ONNX Runtime classes are not obfuscated.
Create or edit android/app/proguard-rules.pro:
-keep class ai.onnxruntime.** { *; }
Or run this command from your terminal:
echo "-keep class ai.onnxruntime.** { *; }" > android/app/proguard-rules.pro
See the flutter_onnxruntime troubleshooting guide for more details.
β‘οΈ iOS
ONNX Runtime requires iOS 16+ and static linkage.
In ios/Podfile, update the following lines:
platform :ios, '16.0'
# ... existing code ...
target 'Runner' do
use_frameworks! :linkage => :static
# ... existing code ...
end
And add to the post_install hook:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0'
end
end
end
β‘οΈ macOS
macOS builds require macOS 14+.
In macos/Podfile, change:
platform :osx, '14.0'
Update the "Minimum Deployments" to 14.0 in Xcode:
open macos/Runner.xcworkspace
Then in Xcode:
- Select Runner project in the navigator
- Select Runner target
- Go to General tab
- Change Minimum Deployments to 14.0
Also add to the post_install hook in your Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '14.0'
config.build_settings['ALLOW_STATIC_FRAMEWORK_TRANSITIVE_DEPENDENCIES'] = 'YES'
end
end
end
Demo #
See
example/for a demo app with language selection, voice switching, and adjustable settings.
More Examples #
Basic Example #
import 'package:supertonic_flutter/supertonic_flutter.dart';
// Initialize
final tts = SupertonicTTS();
await tts.initialize();
// Synthesize speech
final result = await tts.synthesize(
'Hello, world!',
language: 'en',
voiceStyle: 'M1',
);
// Convert to WAV and save
final wavBytes = result.toWavBytes();
final file = File('output.wav');
await file.writeAsBytes(wavBytes);
With Audio Player #
import 'package:supertonic_flutter/supertonic_flutter.dart';
final tts = SupertonicTTS();
final player = TTSAudioPlayer();
// Initialize
await tts.initialize();
// Synthesize and play
final result = await tts.synthesize(
'Hello, this is a test.',
language: 'en',
voiceStyle: 'F1',
config: TTSConfig(
speechSpeed: 1.05,
denoisingSteps: 5,
),
);
await player.play(result);