gpt4 book ai didi

希伯来语的android-TextToSpeech

转载 作者:太空狗 更新时间:2023-10-29 13:30:14 29 4
gpt4 key购买 nike

我试着像这样使用它

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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com