You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			| 
				
					
						
							 | 
			5 years ago | |
|---|---|---|
| .. | ||
| .github | 5 years ago | |
| android | 5 years ago | |
| example | 5 years ago | |
| ios | 5 years ago | |
| lib | 5 years ago | |
| macos | 5 years ago | |
| .gitignore | 5 years ago | |
| CHANGELOG.md | 5 years ago | |
| CODE_OF_CONDUCT.md | 5 years ago | |
| LICENSE | 5 years ago | |
| README.md | 5 years ago | |
| analysis_options.yaml | 5 years ago | |
| pubspec.yaml | 5 years ago | |
		
			
				
				README.md
			
		
		
			
			
		
	
	Text To Speech
A flutter text to speech plugin (Swift,Java)
Features
- Android, iOS, Web, & macOS
- speak
 - stop
 - get languages
 - set language
 - set speech rate
 - set speech volume
 - set speech pitch
 - is language available
 
 - Android, iOS
- get voices
 - set voice
 - speech marks (requires iOS 7+ and Android 26+)
 - synthesize to file (requires iOS 13+)
 
 - iOS, Web
- pause
 
 - Android
- set Silence
 
 - iOS
- set shared instance
 - set audio session category
 
 
Usage
macOS
OSX version: 10.15
Example App from the macOS_app branch
Web
Website from the example directory.
Android
Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.
minSdkVersion 21
iOS
There's a known issue with integrating plugins that use Swift into a Flutter project created with the Objective-C template. Flutter#16049
To use this plugin :
- add the dependency to your pubspec.yaml file.
 
  dependencies:
    flutter:
      sdk: flutter
    flutter_tts:
- instantiate FlutterTts
 
FlutterTts flutterTts = FlutterTts();
To set shared audio instance (iOS only):
await flutterTts.setSharedInstance(true);
To set audio category and options (iOS only):
await flutterTts
        .setIosAudioCategory(IosTextToSpeechAudioCategory.playAndRecord, [
      IosTextToSpeechAudioCategoryOptions.allowBluetooth,
      IosTextToSpeechAudioCategoryOptions.allowBluetoothA2DP,
      IosTextToSpeechAudioCategoryOptions.mixWithOthers
    ]);
To await speak completion.
await flutterTts.awaitSpeakCompletion(true);
speak, stop, getLanguages, setLanguage, setSpeechRate, setVoice, setVolume, setPitch, isLanguageAvailable, setSharedInstance
Future _speak() async{
    var result = await flutterTts.speak("Hello World");
    if (result == 1) setState(() => ttsState = TtsState.playing);
}
Future _stop() async{
    var result = await flutterTts.stop();
    if (result == 1) setState(() => ttsState = TtsState.stopped);
}
List<dynamic> languages = await flutterTts.getLanguages;
await flutterTts.setLanguage("en-US");
await flutterTts.setSpeechRate(1.0);
await flutterTts.setVolume(1.0);
await flutterTts.setPitch(1.0);
await flutterTts.isLanguageAvailable("en-US");
// iOS and Web only
await flutterTts.pause();
// iOS, macOS, and Android only
await flutterTts.synthesizeToFile("Hello World", Platform.isAndroid ? "tts.wav" : "tts.caf");
await flutterTts.setVoice({"name": "Karen", "locale": "en-AU"});
// iOS only
await flutterTts.setSharedInstance(true);
// Android only
await flutterTts.setSilence(2);
await flutterTts.getEngines();
Listening for platform calls
flutterTts.setStartHandler(() {
  setState(() {
    ttsState = TtsState.playing;
  });
});
flutterTts.setCompletionHandler(() {
  setState(() {
    ttsState = TtsState.stopped;
  });
});
flutterTts.setProgressHandler((String text, int startOffset, int endOffset, String word) {
  setState(() {
    _currentWord = word;
  });
});
flutterTts.setErrorHandler((msg) {
  setState(() {
    ttsState = TtsState.stopped;
  });
});
flutterTts.setCancelHandler((msg) {
  setState(() {
    ttsState = TtsState.stopped;
  });
});
// iOS and Web
flutterTts.setPauseHandler((msg) {
  setState(() {
    ttsState = TtsState.paused;
  });
});
flutterTts.setContinueHandler((msg) {
  setState(() {
    ttsState = TtsState.continued;
  });
});
Getting Started
For help getting started with Flutter, view our online documentation.
For help on editing plugin code, view the documentation.