Search code examples
androidtext-to-speechandroid-auto

Text to speech not working on Head Unit and DHU


I am trying to implement Text-to-speech in my android auto app but unable to hear it on Desktop head unit. I have also tried it on Car Head unit but no luck.

below is the code i am using

 TextToSpeech tts=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
     @Override
     public void onInit(int status) {
        if(status != TextToSpeech.ERROR) {
           t1.setLanguage(Locale.UK);
        }
     }
  });

and on button click i am using

 tts.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);

also tried to turn OFF Bluetooth Headset as suggested in xda forums but still same issue.

Do i need to add any extra library like "gear.aar" to make it work for Auto as the code is in CarActivity


Solution

  • speak() method requires four parameters to execute the job I solved this using below code

     tts.speak(readText, TextToSpeech.QUEUE_ADD, null, ""+Calendar.getInstance().getTimeInMillis());