作者:小么么和 | 来源:互联网 | 2023-05-24 09:53
好吧,这是我的代码:
final TextToSpeech ttv = new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {
public void onInit(int status) {
ttv.setLanguage(Locale.US);
Log.e("Init", "Success");
ttvInit = true;
// wait a little for the initialization to complete
Handler h = new Handler();
h.postDelayed(new Runnable()
{
public void run() {
ttv.speak(textSpeech.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
}
}, 400);}
else {
System.out.println("Something went wrong.");
}
}
但我得到一个错误"无法解决方法'postDelayed(java.lung.Runnable,int)'
编辑:它现在告诉我它没有使用:http://www.igreklik.com/slike/viewer.php? file = 75221279105193055086.png&file_imgur =
HPJDlfa.png
1> bonnyz..:
检查您的导入:
import android.os.Handler;
并将您的代码更改为此(您的"其他"语句不正确):
final TextToSpeech ttv = new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {
public void onInit(int status) {
ttv.setLanguage(Locale.US);
Log.e("Init", "Success");
ttvInit = true;
// wait a little for the initialization to complete
Handler h = new Handler();
h.postDelayed(new Runnable()
{
public void run() {
ttv.speak(textSpeech.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
}
}, 400);
}
});