A flutter text to speech plugin which is built in Swift for iOS and Java for Android.
It’s Fully compatible on:
So if you are planning or developing flutter text to speech app then this will helpful for you.
pubspec.yaml
file.dependencies:flutter:sdk: flutterflutter_tts:
final flutterTts = FlutterTts();
await flutterTts.setSharedInstance(true);
await flutterTts.setIosAudioCategory(IosTextToSpeechAudioCategory.playAndRecord, [IosTextToSpeechAudioCategoryOptions.allowBluetooth,IosTextToSpeechAudioCategoryOptions.allowBluetoothA2DP,IosTextToSpeechAudioCategoryOptions.mixWithOthers]);
speak()
function and pass your word and it will speak your word. To stop flutter tts you can call stop()
function from flutterTts instance and it will stop speaking.If you aim is not only speaking word on button click and stop speaking on button click. Then you can use following functions according to your need.
getLanguages()
, setLanguage()
, setSpeechRate()
, setVolume()
, setPitch()
, isLanguageAvailable()
, setSharedInstance()
getLanguages()
is used to get available supported languages on device for flutter text to speech plugin, it Returns a list of available languages.
setLanguage()
is used to set language, for ex. await flutterTts.setLanguage("en-US");
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 onlyawait flutterTts.pause();// iOS and Android onlyawait flutterTts.synthesizeToFile("Hello World", Platform.isAndroid ? "tts.wav" : "tts.caf");// iOS onlyawait flutterTts.setSharedInstance(true);// Android onlyawait flutterTts.setSilence(2);await flutterTts.getEngines();
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 WebflutterTts.setPauseHandler((msg) {setState(() {ttsState = TtsState.paused;});});flutterTts.setContinueHandler((msg) {setState(() {ttsState = TtsState.continued;});});
LESSONS
COURSES
TUTORS
Quick Links
Legal Stuff
Social Media