Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

text_to_speech_plus πŸŽ™οΈ

Pub Version License: MIT

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, and Gender info.
  • ⏱️ 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 21 or 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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages