我正在开发一个使用第三方tts的应用程序,名为flite。我正在做一些类似于TTS说句话的事情。我想突出显示每个单词。为此,我设法从tts获得了字级回调。 工作流程就像这样 - 按下“发言文本”按钮。它启动tt服务,然后将文本发送到C语言的过滤器,并与应用程序结合使用。 现在,从C代码开始,每个单词之后我会对两个不同的java活动进行两次回调: 一到tts服务说出单词 秒我的测试java活动突出显示该单词。 我成功地在我的测试活动中获得了单词级回调,但之后我无法执行任何UI工作。android runonuithread()函数不执行
以下是我在获取回调时执行的代码: 这是从C代码调用的函数。
private void WordCallback(int isword) {// from
// callback
if (isword == -1) {
Log.d(LOG_TAG, "its not a word");
} else if (isword == -2) {
Log.d(LOG_TAG, "yeah..its the end");
} else {
Log.d(LOG_TAG, "its word no " + isword);
int word = isword;
Log.d(LOG_TAG, "highlightwords");
highlightwords(isword);
if (isword == 4) {
Log.d(LOG_TAG, "in if");
new Thread(new Runnable() {
@Override
public void run() {
Log.d(LOG_TAG, "thread started");
try {
Flitetest.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(LOG_TAG, "run on ui");
textview.setText("#" + isword);
}
});
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
}
FliteTest是活动的名称。 日志打印直到“线程启动”,但runonuithread()中的代码永远不会执行,并且也没有错误。
而且,如果写不textview.settext("something")
线程和runonuithread(),它给人的错误:
fatal signal 11(sigsegv) at 0x6fc64e87(code=1), thread 20292(SynthThread)
。
该行为的原因是什么?
好的,你可以请解释这将如何解决我的问题? –