我正在使用Nuance Android SDK。我在取消另一个识别器后立即尝试初始化一个新的识别器。但是,现在似乎新的识别器在此之后出错了。
所以我想要发生的是取消识别器并在一次按钮点击中初始化一个新的识别器。如果我按两次按钮点击它就可以完美地工作,但是当我试图通过一次按钮点击它时它总是会出错。以下是代码:
@Override
public void onClick(View v) {
if (_currentRecognizer != null)
{
_currentRecognizer.stopRecording();
}
_currentRecognizer = MainActivity.getSpeechKit().createRecognizer(Recognizer.RecognizerType.Dictation, Recognizer.EndOfSpeechDetection.Long, Constants.Speech2TextTable.get(source), _listener, _handler);
_currentRecognizer.start();
isRecording = true;
}
在控制台中,它返回以下内容:
07-27 17:13:02.464 5415-5458/com.sws.translate I/SpeechKit﹕ Starting recognize transaction
07-27 17:13:02.464 5415-5460/com.sws.translate D/NMSP_﹕ [co] loadResource
07-27 17:13:02.464 5415-5460/com.sws.translate E/NMSP﹕ [b] ANDROID_CONTEXT parameter is not passed in!!!
07-27 17:13:02.484 5415-5460/com.sws.translate E/NMSP﹕ [b] ANDROID_CONTEXT parameter is not passed in!!!
07-27 17:13:02.484 5415-5460/com.sws.translate I/NMSP﹕ [dk] appendLogToQueryBegin: NMSPDefines.DEVICE_CMD_LOG_TO_SERVER_ENABLED is disabled
07-27 17:13:02.484 5415-5458/com.sws.translate I/SpeechKit﹕ Starting recorder
07-27 17:13:02.484 5415-5460/com.sws.translate D/NMSP_﹕ [dk] PDXCommandCreated() called from handleInit()c7c85b31-e625-49ab-a239-2f9d6c28876a:12 (com.nuance.nmdp.speechkit.dk@42ca4d48,com.nuance.nmdp.speechkit.r$1@42ca3bc0)
07-27 17:13:02.684 5415-5458/com.sws.translate I/SpeechKit﹕ Capturing audio from recorder
07-27 17:13:04.454 5415-5458/com.sws.translate I/SpeechKit﹕ Stopping recorder
07-27 17:13:04.624 5415-5460/com.sws.translate I/SpeechKit﹕ Recorder stopped
07-27 17:13:04.624 5415-5458/com.sws.translate I/SpeechKit﹕ Transaction error code: 5
07-27 17:13:04.624 5415-5458/com.sws.translate D/NMSP_﹕ [cp] freeResource() disconnectTimeout:0
07-27 17:13:04.624 5415-5458/com.sws.translate I/SpeechKit﹕ Starting recognize transaction
07-27 17:13:04.624 5415-5460/com.sws.translate D/NMSP_﹕ [co] loadResource
07-27 17:13:04.634 5415-5460/com.sws.translate E/NMSP﹕ [b] ANDROID_CONTEXT parameter is not passed in!!!
07-27 17:13:04.634 5415-5460/com.sws.translate D/NMSP_﹕ [co] loadResource
07-27 17:13:04.634 5415-5460/com.sws.translate E/NMSP﹕ [b] ANDROID_CONTEXT parameter is not passed in!!!
07-27 17:13:04.634 5415-5460/com.sws.translate E/NMSP﹕ [b] ANDROID_CONTEXT parameter is not passed in!!!
07-27 17:13:04.634 5415-5460/com.sws.translate I/NMSP﹕ [dk] appendLogToQueryBegin: NMSPDefines.DEVICE_CMD_LOG_TO_SERVER_ENABLED is disabled
07-27 17:13:04.634 5415-5458/com.sws.translate I/SpeechKit﹕ Starting recorder
07-27 17:13:04.634 5415-5460/com.sws.translate D/NMSP_﹕ [dk] PDXCommandCreated() called from handleInit()c7c85b31-e625-49ab-a239-2f9d6c28876a:14 (com.nuance.nmdp.speechkit.dk@4250f4e8,com.nuance.nmdp.speechkit.r$1@424f0be8)
07-27 17:13:04.844 5415-5458/com.sws.translate I/SpeechKit﹕ Capturing audio from recorder
07-27 17:13:10.854 5415-5460/com.sws.translate I/SpeechKit﹕ Recorder event (end of speech)
07-27 17:13:10.854 5415-5460/com.sws.translate I/SpeechKit﹕ Recorder stopped
07-27 17:13:15.694 5415-5460/com.sws.translate D/NMSP_﹕ [dk] PDXTransactionImpl.onQueryRetry()
07-27 17:13:15.694 5415-5460/com.sws.translate D/NMSP_﹕ [dh] PDXQueryRetry.getCause()
07-27 17:13:15.694 5415-5460/com.sws.translate D/NMSP_﹕ [dh] PDXQueryRetry.getName()
07-27 17:13:15.694 5415-5460/com.sws.translate I/SpeechKit﹕ PDX Query Retry Returned: 1(AUDIO_INFO)
07-27 17:13:15.694 5415-5460/com.sws.translate D/NMSP_﹕ [dh] PDXQueryRetry.getPrompt()
07-27 17:13:15.704 5415-5460/com.sws.translate D/NMSP_﹕ [dh] PDXQueryRetry.getName()
07-27 17:13:15.704 5415-5458/com.sws.translate I/SpeechKit﹕ Transaction error code: 2
07-27 17:13:15.704 5415-5458/com.sws.translate I/SpeechKit﹕ Transaction suggestion: Sorry, speech not recognized. Please try again.
07-27 17:13:15.714 5415-5458/com.sws.translate D/NMSP_﹕ [cp] freeResource() disconnectTimeout:0
07-27 17:13:15.744 5415-5415/com.sws.translate D/Nuance SampleVoiceApp﹕ Recognizer.Listener.onError: session id [c7c85b31-e625-49ab-a239-2f9d6c28876a]
感谢您的任何建议。
答案 0 :(得分:1)
我很久以前就在使用Speechkit SDK。我相信这里的问题是你的第二个事务在硬件识别器实际停止后开始。当您收到“录音机事件(演讲结束)”时,此事件将停止当前录音机,因此您不录制音频。
您可以在终止录像机之前尝试等待语音结束事件,或者如果允许,您可以使用相同的录像机对象进行第二次识别。添加初始“录制开始声音”有时会修复此类问题。如果没有解决,请尝试在developer.nuance.com上使用Nuance论坛或支持页面