skip to Main Content

I was making an app in flutter which used the flutter_tts package. The flutter text to speech worked perfectly on the emulator, but when I built the app on a real device, it does not function.

speak(String text) async {
      await flutterTts.setLanguage('ro');
      await flutterTts.setPitch(1.0);
      await flutterTts.speak(text);
    }

This is the code snippet that enables the talk function.

Can someone help me identify the issue please?

P.S. I am kind of a noob to stackoverflow so I don’t really know if I should add any extra stuff, so tell me if you need anything.

I tried searching up the problem on the internet with 0 succes, and some help on at least what coul be the problem would be apreciated.

2

Answers


  1. Chosen as BEST ANSWER

    So basically I found the issue,

    You have to set the system language to whatever language you have on your text to speech. Got really scared there :).


  2. Before setting the language check if the language is available on the device using the isLanguageAvailable() method

    try {
      var language = 'ro';
      var isLanguageAvailable = await flutterTts.isLanguageAvailable(language);
    
      if (isLanguageAvailable) {
        await flutterTts.setLanguage(language);
        await flutterTts.setPitch(1.0);
        await flutterTts.speak(text);
      } else {
        print('Language $language is not available on this device.');
      }
    } catch (ex) {
      print('Unexpected error: $ex');
    }
    

    If you go to your "Settings" and then search for "Text-to-speech output" you can see your available languages.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search