0

I am using TextToSpeech in a background service. It works fine with my device speaker and now I want to play that audio on Bluetooth device but TTS doesn't allow me to do so. So is there any way to achieve this.

I also searched on the internet that how TTS worked on Bluetooth but I don't found anything.

My Code:

myTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int i) {
            if (myTTS.getEngines().size() == 0) {
                Toast.makeText(AssistantService.this, "There is no TTS", Toast.LENGTH_SHORT).show();
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    myTTS.setLanguage(Locale.forLanguageTag("hi-in"));
                    myTTS.setVoice(new Voice("hi-in-x-cfn#male_3-local", Locale.forLanguageTag("hi-in"), Voice.QUALITY_VERY_HIGH, Voice.LATENCY_NORMAL, false, null));
                }
                speak("          " + "Hello Sir, मै आप के लिए क्या कर सकता हूँ");
            }
        }
    });
Shubham Gupta
  • 1,123
  • 11
  • 16
  • It might help if you edit the question to include: 1) if the phone is connected to bluetooth shouldn't all audio be routed to that bluetooth device by default? What behavior were you expecting and when you say "the TTS doesn't allow me to do so" , what exactly is happening and how does that differ from what you expected? 2) If you want to convert the TTS to audio and then play the audio, why do you say (in title) *wihtout saving to storage* -- wouldn't storage be a necessary step in the conversion ie using synthesizeToFile() ? – Nerdy Bunz Jul 07 '20 at 20:04
  • Hey Nerdy Bunz, I edited this question by your 1st option, Now can you help me! – Shubham Gupta Jul 09 '20 at 08:52
  • if the phone is connected to bluetooth shouldn't all audio be routed to that bluetooth device by default? What behavior were you expecting and when you say "the TTS doesn't allow me to do so" , what exactly is happening and how does that differ from what you expected? – Nerdy Bunz Jul 09 '20 at 21:57
  • TTS not playing audio over my Bluetooth headphones but work fine with divice speaker. – Shubham Gupta Jul 10 '20 at 03:14
  • Well, unfortunately I don't know the answer. But at least you revised your question and so it's more likely to be seen and answered. You might try testing different devices and different tts engines -- Google vs Samsung, etc. Also there is this: https://stackoverflow.com/questions/15392457/how-to-text-to-speech-plays-on-bluetooth-in-android – Nerdy Bunz Jul 10 '20 at 04:57

0 Answers0