I'm trying to set the language of my TextToSpeech-object to Dutch. This is the default language of my Android tablet on which the app will run, and when I log Locale.getDefault() I get "nl_NL"so this is correct.
I've read that for TTS you need to supply the ISO Language Code and ISO Country Code when setting the language with Locale. But here is the problem: when the tablet does not have an Internet connection, the TTS doesn't seem to be able to set the language to Dutch. Here is my code for setting the language:
int result = tts.setLanguage(new Locale(Locale.getDefault().getISO3Language(),
Locale.getDefault().getISO3Country()));
// this equals to "nld","NLD"
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED)
{
tts.setLanguage(Locale.UK);
}else{
dutch = true;
}
Without Internet connection, the language is always set to Locale.UK. With Internet connection, it works as intended and the language is set to Dutch (I don't even have to provide the ISO-notation, just new Locale("nl_BE") or "nl_NL" will do).
Further in my code when the TTS.speak is called I always check if Dutch is true, and then a Dutch string is providedfor the speak method, otherwise an English string is provided.
How can I fix this that I can set the TextToSpeech language to Dutch without Internet connection?
EDIT: for other people experiencing my issue, check out the edited part of my answer below.
After a lot of research it seems that the standard languages that are installed with TTS do not contain the Dutch language.
I ran some test using the method isLanguageAvailable(Locale loc) and thereby checking for Dutch language etc., and it seems that the Dutch language is not supported (the returned value is LANG_NOT_SUPPORTED ).
I'll have to find another TTS-client to meet my needs or to play .mp3-files with the correct message (this could work because the values that the TTS had to pronounce were predefined).
Some links that helped me:
http://igordcard.blogspot.be/2014/02/changing-android-text-to-speech-tts.html
Missing languages in TTS android
How to check if a specific language data for Text to Speech(TTS) is installed on a device?
http://code.tutsplus.com/tutorials/android-sdk-using-the-text-to-speech-engine--mobile-8540
And an image showing which languages were installed:
EDIT: after updating the "Google TTS"-app from Google Play Store, Dutch BECAME available. If you're looking for Dutch offline TTS and you're using the Google TTS for it, just update it to the latest version.
Try
tts.setLanguage(new Locale("nl", "NL"));
Related
Hello Guys
I am developing a dictionary application where users can search Arabic <-> Turkish. I'm getting the data from firebase, no problem here. In my algorithm, the user's keyboard language is selected when the user presses the search view. If this language is Turkish, the text entered by the user is listed as Turkish in the search view (+recycle view), sends it to the recycle view and is listed. If that language is Arabic, I list it as Arabic. By the way, you can think of the data I listed as key & value. The Turkish equivalent of each Arabic word is on the same line. So far the app is working fine for me because I am using my phone's default keyboard and I can get the keyboard language.
The problem starts here;
I can't get this keyboard language when user uses custom keyboards published in Play Store. I can't list it because I can't get the keyboard language. I opened a thread on Stackoverflow but was told that I can't access the language of these custom keyboards in any way. So, how can I sort by understanding whether the user is searching in Arabic or Turkish, without picking up the keyboard language or in any way asking the user in which language to search? Thanks in advance and good work.
You will have to maintain a translation in your server, when user searches in one language the corresponding meaning in other language should also be searched, the corresponding meaning will be stored on the server(or on client).
If you can't reliably get the keyboard's locale, that seems like a no-go for what you want to do. But even if someone's using a Turkish keyboard, that doesn't mean they're typing Turkish text, right? Since it basically covers the latin character set - they could even be typing in romanised Arabic! (I don't know how likely that is, but it's possible)
You might want to look into a library that detects languages - from a quick search there are a few, and ML-Kit is a Google library that people seem to recommend for it.
I think whatever you do, you probably want the user to be able to set their input language explicitly - give them the final say (and responsibility for ensuring it's correct!). Similar to how Google Translate does it - you can type and it can guess what language you're using (and it says something like (automatically detected) next to it) but the user gets to explicitly choose
edit since you really want this to be automatic (I'd really recommend giving the user control over this, just in case) could you do something like checking if the characters they've entered are Arabic script?
Doesn't help with romanised Arabic (I don't know if that's really used much at all!) - but if you can assume Arabic uses Arabic script, and Turkish is anything else (or you could do the same with the Turkish characters) then maybe you could take a guess just by comparing their input to a set of potential characters. There might even be a convenient Unicode grouping you can check, but I'm not sure off-hand. Might be worth looking into
I'm developing a project where I need to automatically determinate which is the user language used to created the content.
We're actually using Locale.getDefault().getLanguage() but this can not be the right choice because, for istance, I live in Italy, I write content in Italian but my default Locale on my phone is en_US.
So I tought that maybe I could determinate it from the SIM Country (and fallback to user Locale when the device does not have one) but there's no one-to-one relation from a Country to a Language. For istance, US has en_US and es_US.
Do you have any suggestion? Should I ask the user for their current content's Locale?
What's the reason you need the user language?
I too have my locale set to en_US, and I have that because I prefer to have menus etc in English. (The translation of menus and settings etc feels strained in my native language.)
Chances are that your users will be annoyed (I know I would) if you use anything other than Locale.getDefault().getLanguage() for whatever you're using the language for.
That being said, if you really want to use a local language, I suggest you figure out the country code by some heuristics based on
Default locale
SIM country
Current network country
and use a hard coded lookup table from country code to (one of) the official language code(s). There are open databases with this information, see for example these resources:
List of language codes by country
Country codes / language codes on the OpenStreetMap wiki
Here is how my code looks.
//loc will be either "ru-RU" or "en-US"
speechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, loc);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, loc);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, loc);
Problem is that, when I am using the program with different phones it works well.But with my cell phone it always chooses default language. And rare times it is just mixing recognition languages. Like half of the result is in one language other half in another language.
I dont know whether it is cause of system or from code itself?
Plus It worked well before on my phone too. Can it be cause of some settings?
How can I overcome and fix it? I need to know to inform users how to fix it if they will have the same problem
How can I use voice recognition with other languages android
SpeechRecognizer with Google Search version 3.6.14.1337016 can't recognize other voice language except default
Firstly, the problem exists while using SpeechRecognizer
On this case only solution was to delete google search cause it is related to google search update. Doing so we will delete all updates. This worked on my own device
But on my opinion,actually, small updates should not change api behaviour. I hope there is programmatic way to solve this issue or there will be new update that will fix it
Here is undocumented programmatic solve:
intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new
String[]{});
it is artetxem's answer
Other solution is just to call activity for recognition. This way google's dialog activity will be seen but there will be no language problems.
Issue opened by me issue
Issue opened on google search by artetxem issue
Hi #VSL i was also facing same problem to set language hindi instead of english, but Speech recognizer always take my Android OS default language which is english. But below code solved my problem
Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, InteractionActivity.this.getPackageName());
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
speech.startListening(recognizerIntent);
I want to use http://translate.google.com/ to translate the string.
And now I want to sent a string from a java program in http://translate.google.com/ to translate the string from english to bangla .
And I want to get the translated string as a program output .
Anyone can tell me how can I do this......??
The wrong way to do that : use an HTTPClient to emulate, in Java, a browser request.
It's a bad way of using a website, as you'll make dirty things in HTTP, and your program will have to be modified each time Google modify the HTML pages on translate.google.com (even if that should be pretty rare).
The right way of doing that : use the Google Translate API provided by Google for that purpose. It's just a REST service so it works quite easily in JAVA.
Beware that the number of translations that you can do each day is, as far as i remember, limited to a certain amount each day (check the online conditions on the API website). At first glance after just checking that, it seems that the v2 API is not free anymore, i don't know if you can stick to the v1 one.
If google is not a must you can consider Bing translator. Here is a link on how to use the free APIs as well (the example uses C# but you can easily write the same in JAVA). We are using this in our project and it works quite well.
I used this code on my button for translate:
String translate = "translate this string";
String locale = Locale.getDefault().getLanguage();
Uri uri = Uri.parse("https://translate.google.com/#auto/"+ locale + "/" + translate); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
getApplicationContext.startActivity(intent);
I used #auto to detect automatic from string translate, and locale to detect locale language from phone.
Hope this helps :)
Easy task.
Use this - http://translate.google.com/#{fromLanguage}|{toLanguage}|{your_string_here}
Just replace languages with yours (you can check it in translator - short names)
And add your string that you want to translate.
You can make request to this site
result = tts.setLanguage(Locale.CHINA);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
}
I have some text that are in English inside my string which I believe is the cause of the log message which says that the language is not supported.
My question is that is there a way to by pass this exception or should I try to eliminate all the English words on my string then perform the translation?
Also another question is "what other possible exceptions of failure to TextToSpeech?".
EDIT: this answer is obsolete. Android supports Chinese now.
Android does not support Chinese out of the box. The docs state:
The TTS engine that ships with the Android platform supports a number
of languages: English, French, German, Italian and Spanish.
A Chinese engine might be available for download on the Market. Try the one called "SVOX Classic" - it supports downloadable voices for a large variety of languages.
Also, see this question.