text_to_speech_plus 1.0.0
text_to_speech_plus: ^1.0.0 copied to clipboard
A modern Flutter plugin for Text-to-Speech (TTS) capabilities across Android, iOS, Web, Windows, and macOS.
text_to_speech_plus 🎙️ #
text_to_speech_plus is a modern, high-performance Flutter plugin for Text-to-Speech (TTS). It is designed for developers who need more than just basic voice output, offering advanced features like SSML, Real-time Visualization, Streaming, and Emotional Expression.
Compatible with: Android, iOS, Web, Windows, and macOS.
🚀 Top Features #
- 🎭 Expressive Styles: Use
Cheerful,Angry,Sad,Whisper, and more. - ⚡ AI-Ready Streaming: Enqueue chunks of text for immediate playback while your AI generates more.
- 📜 Full SSML Support: Precise control over pauses, emphasis, pronunciation, and volume.
- 👥 Multi-Speaker: Switch between different voices mid-conversation with zero delay.
- 📊 Real-time Amplitude: Build waveforms or sync character lip-movements with actual speech volume.
- 🔍 Smart Voice Discovery: Deep metadata including
Neural,Premium, andGenderinfo. - ⏱️ Precise Timestamps: Know exactly when every word or sentence is spoken.
- 🧠 Auto Language Detect: Automatically select the right voice based on input text script.
📦 Installation #
Add to your pubspec.yaml:
dependencies:
text_to_speech_plus: ^1.0.0
Setup Requirements #
- Android:
minSdkVersion 21or higher. - iOS: Target
12.0+(Advanced SSML requires iOS 17.0+). - macOS: Target
10.15+.
📖 Feature Showcase & Code #
1. Advanced Expressions & Emotions #
Request specific vocal tones to match the mood of your app.
final tts = TextToSpeechPlus();
// Speak with a specific style
await tts.speak("I am so excited to see you!", style: "cheerful");
// Or inject emotional context
await tts.speak("I'm sorry, I cannot do that.", emotion: "sad");
2. ⚡ Streaming (Enqueueing) for AI Chat #
Ideal for LLM integrations (like OpenAI or Gemini). Start speaking the first sentence as soon as it arrives!
// First sentence speaks immediately
await tts.speak("The weather in London is ", enqueue: false);
// Next chunks are added to the queue for seamless playback
await tts.speak("currently rainy with a high of 15 degrees.", enqueue: true);
await tts.speak(" I suggest taking an umbrella!", enqueue: true);
3. 📊 Real-time Audio Visualizer #
The onAmplitude callback provides the volume level (0.0 to 1.0) of the audio being output.
tts.onAmplitude((double amplitude) {
// Use this value to drive a waveform widget or an avatar's mouth
setState(() {
mouthOpenness = amplitude;
});
});
await tts.speak("Watch the visualizer react to my voice!");
4. ⏱️ Live Word & Sentence Highlighting #
Synchronize your UI with the spoken text for reading or accessibility apps.
// Word-level progress
tts.onProgress((text, start, end, word, type) {
print("Now speaking word: $word");
});
// Sentence-level detection
tts.onSentenceStart((text, start, end, sentence, type) {
print("Beginning new sentence: $sentence");
});
5. 📜 SSML Playground #
Full support for Speech Synthesis Markup Language.
await tts.speakSsml("""
<speak>
<p>First, I will speak normally.</p>
<p><emphasis level="strong">Then with strong emphasis!</emphasis></p>
<p>I can also <break time="2s"/> pause for two seconds.</p>
<p><prosody pitch="high">And speak in a high pitch.</prosody></p>
</speak>
""");
6. 🗣️ Multi-Speaker Dialogs #
Define unique voices for different characters in a single session.
final voices = await tts.voices;
final maleVoice = voices.firstWhere((v) => v['gender'] == 'male');
final femaleVoice = voices.firstWhere((v) => v['gender'] == 'female');
await tts.speak("How are you doing today?", voice: maleVoice);
await tts.speak("I'm doing fantastic, thank you!", voice: femaleVoice, enqueue: true);
7. 🔍 Voice Discovery & Search (Gender, Type, Locale) #
Filter system voices to find exactly what you need, such as a Male or Female neural voice.
List<dynamic>? allVoices = await tts.getVoices();
// Find all premium female English voices
var myVoices = allVoices?.where((v) =>
v['locale'] == 'en-US' &&
v['gender'] == 'female' &&
v['is_neural'] == '1'
).toList();
if (myVoices != null && myVoices.isNotEmpty) {
await tts.setVoice(Map<String, String>.from(myVoices.first));
}
9. 👫 Changing Voice Gender #
Most TTS engines provide multiple voices per language. You can change the gender by selecting a specific voice that matches your preference.
List<dynamic>? allVoices = await tts.getVoices();
// Find a Male voice for English
var maleVoice = allVoices?.firstWhere((v) =>
v['locale'] == 'en-US' && v['gender'] == 'male'
);
if (maleVoice != null) {
await tts.setVoice(Map<String, String>.from(maleVoice));
}
🎧 Unified Event Callbacks #
| Event | Description |
|---|---|
onStart |
Synthesis has started. |
onComplete |
An utterance has finished. |
onQueueFinished |
The entire queue (all enqueued text) is empty. |
onProgress |
A word or sentence boundary was reached. |
onSentenceStart |
A new sentence has begun speaking. |
onAmplitude |
Real-time audio volume level (0.0 to 1.0). |
onVoiceChanged |
The speaker or language was updated. |
onError |
An error occurred during speech. |
📋 Full API Reference #
| Method | Parameters | Description |
|---|---|---|
speak |
text, enqueue, style, emotion, voice, readingOptions, autoDetectLanguage |
Main speech method with all modern overrides. |
speakSsml |
ssmlText, enqueue |
Helper for raw SSML input. |
setVolume |
double (0.0 - 1.0) |
Sets the global volume level. |
setRate |
double (0.0 - 1.0) |
Sets the global speed (mapped across platforms). |
setPitch |
double (0.5 - 2.0) |
Sets the vocal pitch. |
getVoices |
- | Returns all available system voices with metadata. |
stop / pause |
- | Controls the current synthesis session. |
⚖️ License #
This project is licensed under the MIT License - see the LICENSE file for details.
Developed with ❤️ by Shirsh Shukla.