Text to speech android for chinese - java

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.

Related

How can i do a search view search in two different languages?

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

Android detect speech recognition language

I am working in an application that recognizes user voice and convert it to decimal , it should detect two languages Arabic , and English.
This my Intent to detect user input:
Intent voicerecogize = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voicerecogize.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "ar-eg");
startActivityForResult(voicerecogize, RESULT_SPEECH);
I need a method to detect which language user speaks either Arabic or English.
You can not listen for 2 languages at the same time with the current Android Speech Recognition API.
You can only listen for one language at a time.
What you could do is record the user input and then push the recorded input to one speech recognizer for English and one for Arabic, but there is no out-of-the-box API to do this.

Android - TTS set language to Locale.getDefault not possible without internet?

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"));

How can I use http://translate.google.com/ to translate the string in Java program?

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

How to determine if the user prefers simplified or traditional Chinese characters

In an Android app, is there a standard way to determine whether a user prefers simplified or traditional Chinese characters?
I know next to nothing about Chinese, but I do know from Wikipedia that simplified Chinese is used in mainland China (locale zh_CN) and Singapore whereas traditional Chinese is used in Taiwan (locale zh_TW), Hong Kong, and Macau. Differentiating on the country code might be acceptable for the initial choice, but it would be problematic for someone in mainland China who prefers traditional characters, or someone in Hong Kong who prefers simplified characters. Is there a global setting for this preference?
If I must resort to an app-specific setting, is there an ad hoc standard way of sharing this information with other apps?
Just treat it as how you'd treat any other two languages. Don't rely on region. Just go with what the user has set in their default locale.
To check for the default locale:
Locale myPhoneLocale = Locale.getDefault();
If you want to translate your strings.xml file for both traditional and simplified, just make a values-zh-rCN folder and throw simplified in there, and another values-zh folder for traditional.
Most Chinese users are able to read both simplified and traditional. (Some might be annoyed at having to read the one they are less used to, but it's not the end of the world.) I personally only localize my apps to simplified Chinese, since mainland China has the most android users.

Categories

Resources