Unable to speak languages except English - java

In my android TTS application, I tried to speak out Japanese. So, I set the language to Japanese.
result = tts.setLanguage(Locale.JAPAN);
finalText = textField.getText().toString();
tts.speak(finalText , TextToSpeech.QUEUE_ADD, null);
This didn't work. So I set to
result = tts.setLanguage(Locale.JAPANESE);
finalText = textField.getText().toString();
tts.speak(finalText , TextToSpeech.QUEUE_ADD, null);
This also didn't work.
The wonderful case is, any other language except English is not working!!!!!!!!!!!!!!!
This is the text I tried to speak
私は英雄です。だから問題は何ですか?
So my question is, what is happening here? Can't it speak out other languages?
UPDATE
This started working as soon as I set the language in onInit() . Previously, I tried to set on user request, which means, onInit() is not called when the user manually change the language from US to Japanese. So, how can I call the OnInit() manually, without restarting the activity?

Write code as
in onCreate()
String Text = text.getText().toString();
tts.speak(Text, TextToSpeech.QUEUE_ADD, null);
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
then
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("TTS", "This Language is not Supported");
}else{
talk.setEnabled(true);
speakOut();
}
}
else{
Log.e("TTS", "Initialization Falied");
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
tts = new TextToSpeech(this, this);
}
else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
this will give you the option of selecting the voice service there you can Download the Japnese language

Check the return value;
http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#setLanguage(java.util.Locale)
It appears that if the locale you're trying to set is not available (on your phone) it will set the nearest available Locale which in your case might be only english

it not working because your default language select in your phone is English, you need to change it to your desired language or if the package is not available of the desired language you need to download it.
phone setting->language &input->google voice typing->languages.
yet your problem not solve than commenting me your problem.

Related

Allow app unpinning with pin even with device ownership set to this app

I am setting device ownership for my app using dpm command (dpm set-device-admin) and in my MainActivity.java I have placed the code below :
DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
// get this app package name
ComponentName mDPM = new ComponentName(this, MyAdmin.class);
if (myDevicePolicyManager.isDeviceOwnerApp(this.getPackageName())) {
// get this app package name
String[] packages = {this.getPackageName()};
// mDPM is the admin package, and allow the specified packages to lock task
myDevicePolicyManager.setLockTaskPackages(mDPM, packages);
startLockTask();
} else {
Toast.makeText(getApplicationContext(),"Unable to auto pin - not device owner", Toast.LENGTH_LONG).show();
}
Whenever my app starts it auto pins itself, making it unable for users to leave. Without setting device ownership I am able to leave 'pinned' state by long pressing back button and providing the pin.
When I set the ownership this actions is overrided - all I see is 'App is pinned : unpinning isn't allowed on this device'. Is there any way to enable unpinning by providing pin as without device ownership? I still need it to make sure it autopins without any prompts.
Possible answer:
Override single/long key press, request pin and unpin app on success
MainActivity.java
#Override
public void onBackPressed() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
Intent intent = km.createConfirmDeviceCredentialIntent(null, null);
if (intent != null) {
startActivityForResult(intent, REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS);
}
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) {
// unpin the app
if (resultCode == RESULT_OK) {
stopLockTask();
} else {
// nope
Toast.makeText(this, "Pin is not correct", Toast.LENGTH_SHORT).show();
}
}
}

onactivityresult() is never called

I am trying to send mail from my app.The problem is after successful/unsuccessful delivery of the email it doesn't return to the activity, meaning that onActivityResult() is not being called.
Here is my code:
String[] recipients = {"soham#gmail.com"};
Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
// prompts email clients only
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, recipients);
try{
// the user can choose the email client
startActivityForResult(Intent.createChooser(email, "Choose an email client from..."), 1);
}catch(android.content.ActivityNotFoundException ex){
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == 1){
if(resultCode == RESULT_OK){
}else if (resultCode == RESULT_CANCELED){
}
}
}
I have checked this but not working for me. Can anyone tell me what am I doing wrong.
Edit
I got the problem.It will work fine in Activity.But it will not work on Fragment or FragmentActivity. All fragment is closing down forcefully.You can say my app is going on the background.How to solve this issue?Anybody got any idea.
If i uderstand your problem correctly;
In your activity's onActivityResult part you can find your fragment
YourFragment fragment = (YourFragment)getSupportFragmentManager().findFragmentById(R.id.your_framelayout_id);
And use your fragment's public method:
if(fragment != null)
{
fragment.yourPublicMethod();
}
In yourPublicMethod you can do whatever you want. I hope this helps you.

ZXing SCAN_RESULT if statements

this is my first question on stack*overflow*!
I am using Eclipse with Android Development Tools. I have copied the code from GitHub - ZXing to scan a QR code using Barcode Scanner (many of you have seen this code before, I'm sure):
public void onClick(View v)
{
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent,0);
}
I am able to get the Barcode Scanner started and it returns results in the onActivityResult() method.
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == 0)
{
if (resultCode == RESULT_OK)
{
contents = intent.getStringExtra("SCAN_RESULT");
format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
if(contents == "1")
{
contentsLat = contents;
}
else if(contents == "0")
{
contentsRow = contents;
}
else
{
Toast.makeText(getApplicationContext(), "Code Not Recognized\n"+contents+"\n1", Toast.LENGTH_LONG).show();
}
}
else if (resultCode == RESULT_CANCELED)
{
// Handle cancel
Toast.makeText(getApplicationContext(), "Unsuccessful Scan", Toast.LENGTH_SHORT).show();
}
}
}
However, the else statement is always executed...unless I explicitly equate contents to 1. Below is a link to the screenshot (I don't have embedded image privileges yet) of the else body being executed and the toast clearly indicates that contents=1. What have I done wrong? Did I miss something?
Thanks everybody.
Welcome to stackoverflow!
I have seen this is a very common issue in new Java programmmers :), for String comparison we must use the equals() method.
Change your code to:
// Handle successful scan
if(contents.equals("1")){
contentsLat = contents;
}
else if(contents.equals("0")){
contentsRow = contents;
}
More info:
Java comparison with == of two strings is false?
The equals() Method

TTS integration in java application

I am working on a java application which is in fact a back-office for my iOS application (iPhone and iPad)
I need to integrate TTS in my application in order to read mails content in english or french
I searched the net I found many tts engines such as festival or freeTTS but the problem that It doesn't support french
Is there any other TTS engines (free or commercial) that I can integrate in my application???
private TextToSpeech mTts;
protected void onActivityResult
( int requestCode, int resultCode, Intent data)
{
if (requestCode == MY_DATA_CHECK_CODE)
{
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
{
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
}
else
{
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction( TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
mTts.isLanguageAvailable(Locale.FRANCE))
click this link FREETTSenter link description here
STACKOVERFLOW already described similar to this questionenter link description here

No idea what I'm doing with IntentIntegrator

I'm having trouble getting zxing to do anything after scanning a barcode. I call the zxing using:
IntentIntegrator.initiateScan(MainActivity.this);
And my onActivityResult looks like this
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
if (format == "PRODUCT_CODE"){
//If the barcode scanned is of the correct type then pass the barcode into the search method to get the product details
Toast.makeText(getApplicationContext(),"You scanned " + contents, 3).show();
}
else{
//If the barcode is not of the correct type then display a notification
Toast.makeText(getApplicationContext(),"You didn't scan a product code", 3).show();
}
} else if (resultCode == RESULT_CANCELED) {
//If the scan is cancelled then display a notification
Toast.makeText(getApplicationContext(),"You cancelled the input", 3).show();
}
}
}
But whenever I exit zxing nothing is displayed. I tried using the example in the zxing wiki
but whenever I try to replace yourActivity with MainActivity or MainActivity.this I receive errors (I get told MainActivity cannot be resolved to a string and with MainActivity.this that The constructor IntentIntegrator(MainActivity) is undefined).
Basically I have no idea what I'm doing and why it's not working. Any help would be greatly appreciated.
The problem is exactly the same as in your other question. You can't compare strings with ==, but must use equals().

Categories

Resources