android- TextToSpeech希伯来语

时间:2013-05-09 13:41:44

标签: android text-to-speech

我尝试使用这个

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

但我不认为是Locale.iw。

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

“请注意,Java使用了几个弃用的双字母代码。希伯来语(”他“)语言代码被重写为”iw“,印度尼西亚语(”id“)被重写为”in“,而意第绪语(”yi“)被重写为“ji”。即使您构建自己的Locale对象,也不仅仅是针对各种查找方法返回的实例,这种重写也会发生。“

如何在希伯来语中使用textToSpecch?

EDID2:我现在使用新的Locale(“iw”)。它编译但没有声音..(没有英语而不是希伯来语)。只是英语工作正常

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

2 个答案:

答案 0 :(得分:1)

您是否尝试过new Locale("iw")

答案 1 :(得分:1)

我认为希伯来语尚未提供给希伯来语。 我也希望将它用于我的网站,但使用Google TTS。

我认为Android和Google Translater正在使用相同的TTS系统。

在谷歌翻译中,你也听不到希伯来语的表达。 我已经在浏览器和Google Translater App中尝试过它。

示例:https://translate.google.com/#en/iw/Hello

Playstore中有两个希伯来语TTS应用程序:

Aharon Hebrew TTS Ron Hebrew TTS