希伯来语的android-TextToSpeech

标签 android text-to-speech

我试着像这样使用它

int result2 = tts_hebrew.setLanguage(Locale.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);
}
}

最佳答案

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

关于希伯来语的android-TextToSpeech,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16463226/

相关文章:

java - Android - 如何通过文件名获取文件?

android - Xamarin for Android:无法从外部文件夹播放mp3

java - 如何在 Android EditText 中使用土耳其语字符?

c# - 更改文本到语音语音的性别

android - 在 Android MediaRecorder 或使用 AudioRecord 上同时录制两个 channel ?

Android画一条线跟随你的手指

android - 如何在 iOS 和 Android 的 textToSpeech 中使用 ssml 标签?

c# - 是否有任何日语 TTS 语音可与 C# SpeechSynthesizer 一起使用

javascript - SpeechSynthesis.getVoices (Web Speech API) 不显示一些本地安装的声音

android - 无法完成 Retrofit 请求?