-3

我正在尝试创建一个语音识别应用程序,该应用程序可以接收语音并发送内容。我希望调用 onEndOfSpeech 方法的所有内容等待一秒钟,然后执行整个语音识别意图以重新开始。

public void onEndOfSpeech() {
    Log.d("Speech", "onEndOfSpeech");

         try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
        }

不确定我这样做是否正确。谢谢!

4

2 回答 2

1

这是应该的

try {
     Thread.sleep(3000);
     mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
} catch (InterruptedException e) {
     // it depends on your app logic what to do with InterruptedException, you can process it or rethrow or restore interrupted flag
}
于 2013-05-03T05:36:59.537 回答
0

试试这个代码

protected boolean _active = true;
// time to display the splash screen in ms
protected int _splashTime = 1000;
Thread splashThread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
  e.printStackTrace();
  mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
} 
于 2013-05-03T05:40:01.283 回答