3

我尝试像这样使用它

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

但 iw 不被识别为 Locale.iw。

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

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

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

EDID2:我现在使用 new 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);
}
}
4

2 回答 2

1

你试过new Locale("iw")吗?

于 2013-05-09T13:45:14.693 回答
1

我认为希伯来语还不能用于希伯来语。我也想将它用于我的网站,但要使用 Google TTS。

我认为 Android 和谷歌翻译使用相同的 TTS 系统。

在谷歌翻译中你也听不到希伯来语表达。我已经在浏览器和谷歌翻译应用程序中尝试过。

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

Playstore 中提供了两个希伯来语 TTS 应用程序:

Aharon 希伯来语 TTS Ron 希伯来语 TTS

于 2016-09-16T13:00:18.147 回答