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, मै आप के लिए क्या कर सकता हूँ");
}
}
});