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, मै आप के लिए क्या कर सकता हूँ");
}
}
});
Related
If I start the app on an emulator and press the button I can hear the sound, but if it runs on the real device I don't hear any sound (volume level is ca. 80%):
...
t1 = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
Log.d("TTS", "ok");
} else {
Log.d("TTS", "error");
}
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t1.speak("What is your name?", TextToSpeech.QUEUE_FLUSH, null);
}
});
...
According to the output in LogCat everything is fine, but I cannot hear any sound if I press the button:
I/TextToSpeech: Sucessfully bound to com.google.android.tts
I/TextToSpeech: Connected to ComponentInfo{com.google.android.tts/com.google.android.tts.service.GoogleTTSService}
TTS: ok
What can be the problem? Emulator API Level is 4.2.2, device - 4.2.1.
root#android:/ # ls /system/tts/lang_pico/
de-DE_gl0_sg.bin
de-DE_ta.bin
en-GB_kh0_sg.bin
en-GB_ta.bin
en-US_lh0_sg.bin
en-US_ta.bin
es-ES_ta.bin
es-ES_zl0_sg.bin
fr-FR_nk0_sg.bin
fr-FR_ta.bin
it-IT_cm0_sg.bin
it-IT_ta.bin
If your device doesn't have the language installed or doesn't support, it, obviously, can't play it. If it's anything but US, try that...!
does this helped?
I'm trying to reproduce some text with an android aplication that will help visually impaired people, most especially with TTS, but in my case I need Portuguese-Brazil speaking, and the TTS class does not have Portuguese available as locale. Does anyone have any idea how to implement a Portuguese Brazil reader?
I'm using Android Studio, and MinSDK is 15.
...
tts = new TextToSpeech (this, this);
tts.setLanguage(Locale.[X]);
...
tts.speak("Muito obrigado a todos!", TextToSpeech.QUEUE_FLUSH, null);
...
How did you make your onInitListener()? When you call tts = new TextToSpeech (this, this); onInitListener() will connect TextToSpeech service to your tts instance. So, if you try to set language or speak sound, check this value:
tts = new TextToSpeech (this, this);
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int res = tts.setLanguage(Locale.[X]);
if (res >= TextToSpeech.LANG_AVAILABLE) {
// Then, you can speak with your locale.
// Call speak() in here or after this method.
tts.speak("Muito obrigado a todos!", TextToSpeech.QUEUE_FLUSH, null);
}
}
}
Solved! My problem was that on the device was not installed TTS. So, just installed it from the google store(https://play.google.com/store/apps/details?id=com.google.android.tts&hl=en).
I am designing an APP in Android using the TTS Engine.
As the first time, I tried to send the text to google then receive the audio from google via internet, and it is working well.
The next step is to play the TTS audio offline.
That means that I have some text, my Application will get the audio from the system, without connecting to internet.
I have implemented this:
Voice Recognition and Text to Speech
But my problem is TextToSpeech.LANG_MISSING_DATA: this is not working without internet.
If internet is not available, it is not working.
Please help me.
Check out Sifat Ifty's implementation at Text to speech(TTS)-Android
specifically the code block:
tts=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
// TODO Auto-generated method stub
if(status == TextToSpeech.SUCCESS){
int result=tts.setLanguage(Locale.US);
if(result==TextToSpeech.LANG_MISSING_DATA ||
result==TextToSpeech.LANG_NOT_SUPPORTED){
Log.e("error", "This Language is not supported");
}
else{
ConvertTextToSpeech();
}
}
else
Log.e("error", "Initilization Failed!");
}
});
This TextToSpeech.OnInitListener attempts to initialize the tts service if available. Remember to stop the tts service when you are done with it as well!
I had a read aloud menu option which was working fine with the API 15. But fails to work in the API 19. There is no error as such in the code but clicking on the menu doesn't lead to anything. Here is the code:
I have added this in the onCreate
mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
public void onInit(int status) {
if(status == TextToSpeech.SUCCESS)
result=mSpeech.setLanguage(Locale.US);
if(result==TextToSpeech.LANG_MISSING_DATA ||
result==TextToSpeech.LANG_NOT_SUPPORTED){
Log.e("error", "This Language is not supported");
}
}
});
And this is the code i run when the menu is clicked:
case R.id.read_aloud_menu_item:
System.out.println("goes into read aloud case");
System.out.println(TextToSpeech.ERROR);
mSpeech.speak("Hello, this is a sample data", TextToSpeech.QUEUE_FLUSH, null);
I am currently developing an app that makes intensive use of Text-To-Speech (I am using android.speech.tts.TextToSpeech) I have been able to integrate TTS in my voice and at present, a default American US voice is what reads aloud my text.
I would like to know how to make configurational changes to the speech engine. For example, I would like to reduce the speed at which the text is being read, swap between male and female voices and even provide support for different languages. Can anyone please help me with this information. Thanks in Advance :)
[Below is the code I am currently using (courtesy: a very well written basic blog on android TTS), all variable have been declared I am not copying the entire code, and this code snippet works just fine.]
btnSpeak = (ImageButton) findViewById(R.id.ttsIB);
btnSpeak.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
speakOut();
}
});
#Override
public void onDestroy() {
// to shutdown TTS
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
#Override
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
{
Log.e("TTS", "This Language is not supported");
}
else
{
btnSpeak.setEnabled(true);
speakOut();
}
}
else
{
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut()
{
String text = textVal.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
I've worked with TTS a couple of years ago and remember, that there were not so much configuration possibilities.
There is a useful method setEngineByPackageName(String packageName).
Some TTS engines have separate package names for every voice. For example, with Loquendo you need to write tts.setEngineByPackageName("com.loquendo.tts.susan") and your app will speak with US voice Susan.
But some TTS engines has common application and voices as plugins. So, you can configure it only this way:
tts.setEngineByPackageName("com.svox.pico");
tts.setLanguage(Locale.US);
If there are several US voices for this engine, your application will speak with default (selected in phone preferences)