Russian and German support in Google's TTS - android

I'm trying to create an app which would use Google's TTS to read English, German and Russian texts. However currently it only speaks English. The device runs on Android 4.2.1 with Google TTS 3.10.9.
Below is the code I use for testing.
t1 = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.US);
// t1.setLanguage(Locale.GERMANY);
// t1.setLanguage(new Locale("ru"));
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);
// t1.speak("Wie heisst du?", TextToSpeech.QUEUE_FLUSH, null);
// t1.speak("Как Вас зовут?", TextToSpeech.QUEUE_FLUSH, null);
}
});
When I run the same code on an emulator on Android 7 I can hear all the three languages being spoken.
I couldn't find any information which would help me to answer the question: Since which version does TTS support German and Russian? The wiki page only says that the support for Russian was added in 2014. The corresponding Google Play page doesn't have any information related to versions.
When I open the TTS page on Google Play with that device I only see "Installed" button.

The solution was to turn on Wi-Fi on the device and add German and Russian in "Settings -> Language & Input -> Google voice typing -> Voices". After that the languages were downloaded and the app worked as desired.

Related

Android Text to Speech non google engine

In my android app I have a TTS using Google engine.
Have something like this:
tts=new TextToSpeech(MyClass.this, status -> {
if(status == TextToSpeech.SUCCESS){
tts.setLanguage(locale);
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
#Override
public void onDone(String utteranceId) {
if (utteranceId.equals("***")) {
runOnUiThread(() -> {
Button view2 = findViewById(R.id.speech);
view2.setCompoundDrawablesWithIntrinsicBounds(R.drawable.play, 0, 0, 0);
});
}
}
#Override
public void onError(String utteranceId) {
}
#Override
public void onStart(String utteranceId) {
}
});
}
});
Basically I am using 2 languages, slovak and english. Both are working fine with Google TTS.
The problem is, Samsung devices have their own TTS engine set by default and therefore the app text to speech works not on those devices.
After the users changes their device settings to use Google TTS, then it is working.
But is there a way, that my code will support both TTS engines?
I found out that there might work something like this:
TextToSpeech(Context context, TextToSpeech.OnInitListener listener, String engine)
e.g. using com.google.android.tts as the engine parameter.
However in my code I have that like new TextToSpeech(MyClass.this, status -> {... and it doesn't accept engine as a 3rd parameter, and still I don't know how to detect when Samsung engine is needed and switch engines accordingly.
worth trying forcing TTS engine by passing this third param, so exchange very last line in posted snippet
});
to
}, "com.google.android.tts");
there are also two useful methods for you: getDefaultEngine() and getEngines(). just create at start some dummy new TextToSpeech with two params (empty listener) and check what possibilites you have.
also getAvailableLanguages() and isLanguageAvailable(Locale loc) may be useful when Google engine isn't present, but default one still may support your desired langs

Text to Speech(TTS) - Android - Portuguese

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).

how to check TTS already support by device android?

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!

Android Text-To-Speech Configuration and Variations

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)

using eSpeak tts engine in application

I have this code for text to speech in my application.
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
//Setting speech language
int result = tts.setLanguage(Locale.ENGLISH);
//If your device doesn't support language you set above
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
//Cook simple toast message with message
Toast.makeText(this, "Language not supported", Toast.LENGTH_LONG).show();
//Log.e("TTS", "Language is not supported");
}
//TTS is not initialized properly
} else {
Toast.makeText(this, "TTS Initilization Failed", Toast.LENGTH_LONG).show();
//Log.e("TTS", "Initilization Failed");
}
}
My application includes many different languages like English, Hindi, Marathi, Telugu, Tamil, etc. Since the default android tts engine does not support these languages, I downloaded eSpeak tts engine from this link and installed it on my phone.
Its default language is set as English. How do i change its language in my code so that it can read unicode texts of other languages as well?
Currently, for a word in hindi script, it speaks some numbers.
How do i make it recognise the language used in the text? It shows only the locales available in the default google tts. How do I change the tts engine to eSpeak tts?
Initialize your TextToSpeech using
TextToSpeech (Context context, TextToSpeech.OnInitListener listener, String engine)
That is
tts = new TextToSpeech(this, this, "com.googlecode.eyesfree.espeak");
engine Package name of the TTS engine to use, which you can get by calling getEngines.
Try changing the Locale according to your need.
Currently it is Locale.ENGLISH change this accordingly.

Categories

Resources