GO VEGAN
GO VEGAN

Reputation: 1143

android- TextToSpeech in hebrew

I try to use this like

int result2 = tts_hebrew.setLanguage(Locale.iw);

But iw not recognized as Locale.iw.

In http://developer.android.com/reference/java/util/Locale.html :

"Note that Java uses several deprecated two-letter codes. The Hebrew ("he") language code is rewritten as "iw", Indonesian ("id") as "in", and Yiddish ("yi") as "ji". This rewriting happens even if you construct your own Locale object, not just for instances returned by the various lookup methods."

How can I use textToSpecch in Hebrew?

EDID2: I use new Locale("iw") now. It compile but no voice..(no English and not Hebrew) . Just English work fine

package com.example.freeenglish;

import java.util.Locale;
import java.util.Timer;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.Menu;
import android.widget.Button;
import android.widget.EditText;

import com.example.freeenglish.Const;



public class WordLearn extends Activity implements TextToSpeech.OnInitListener  {
//iw -hebrow

    //for speaking
    private TextToSpeech tts_english;
    private TextToSpeech tts_hebrew;
    private Button btnSpeak;
    private EditText txtText;


    int random_word_index;

    int index = 0;
    Button up_english;
    Button down_hebrew;
    Handler hand = new Handler();
    Handler hand1 = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_word_learn);

        up_english = (Button) findViewById(R.id.up);
        down_hebrew = (Button) findViewById(R.id.down);
        hand1.postDelayed(run1, 2000);      

        /////////////////////////////////for speking:
        tts_english = new TextToSpeech(this, this);
        tts_english.setPitch((float) 0.6);//speed. defulat=1, lower<1
        tts_english.setSpeechRate((float) 0.5); //speed. defulat=1, lower<1

        tts_hebrew = new TextToSpeech(this, this);
        tts_hebrew.setPitch((float) 0.6);//speed. defulat=1, lower<1
        tts_hebrew.setSpeechRate((float) 0.5); //speed. defulat=1, lower<1
        ///////////////////////////////////
}



Runnable run1 = new Runnable() {
    @Override
    public void run() {
         random_word_index=(int) (Math.random()*Const.NUMBER_OF_WORDS); 
        up_english.setText(Const.words_list_english[random_word_index]);
        down_hebrew.setText(Const.words_list_hebrew[random_word_index]);

        speakOut_english();
        speakOut_hebrew();

        hand1.postDelayed(run1, 4000);
    }
};

@Override
public void onDestroy() {
    // Don't forget to shutdown tts!
    if (tts_english != null) {
        tts_english.stop();
        tts_english.shutdown();
    }

    if (tts_hebrew != null) {
        tts_hebrew.stop();
        tts_hebrew.shutdown();
    }
    super.onDestroy();
}

@Override
public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {


        int result1 = tts_english.setLanguage(Locale.US);
        int result2 = tts_hebrew.setLanguage(new Locale("iw"));

        if ((result1 == TextToSpeech.LANG_MISSING_DATA || result1 == TextToSpeech.LANG_NOT_SUPPORTED) &&
            (result2 == TextToSpeech.LANG_MISSING_DATA || result2 == TextToSpeech.LANG_NOT_SUPPORTED)   ) {
            Log.e("TTS", "This Language is not supported");
        } else {
            up_english.setEnabled(true);
            down_hebrew.setEnabled(true);
            speakOut_english();
            speakOut_hebrew();
        }

    } else {
        Log.e("TTS", "Initilization Failed!");
    }

}

private void speakOut_english() {

    String text = up_english.getText().toString();

    tts_english.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}

private void speakOut_hebrew() {

    String text = down_hebrew.getText().toString();

    tts_hebrew.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}

Upvotes: 4

Views: 5925

Answers (2)

Grischa
Grischa

Reputation: 80

I think Hebrew isn't yet available for Hebrew. I wanted to use it, too for my website, but with Google TTS.

I think Android and Google Translater are using the same TTS-System.

In Google Translater you can't also hear the hebrew expression. I have tried it in a browser and in the Google Translater App.

Example: https://translate.google.com/#en/iw/Hello

Two Hebrew TTS Apps are avai in the Playstore:

Aharon Hebrew TTS Ron Hebrew TTS

Upvotes: 1

dmon
dmon

Reputation: 30168

Have you tried new Locale("iw")?

Upvotes: 1

Related Questions