neh*_*ain 5 android voice-recognition android-service
我试图了解RecognitionService和RecognitionService.Callback的功能。我对这个框架还很陌生,想知道如何调用 RecognitionService 中的 onStartListening() 函数。我看到了帖子如何注册自定义语音识别服务?但我在所有主要函数中插入了日志消息,以查看何时调用哪个函数。
\n\n我还查看了 sdk 中的示例应用程序,但它在解释事情如何发生方面做得相当糟糕。我想从活动中调用 startService 。
\n\n我使用以下意图
\n\nIntent startServiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);\n startServiceIntent.setClass(this, SimpleVoiceService.class);\n\n startService(startServiceIntent);\nRun Code Online (Sandbox Code Playgroud)\n\n有人可以帮助\xc2\xa0me 使其正常工作吗?如果有人能给我指点这方面的教程,或者描述如何做到这一点的一般流程,那就太好了。
\n\n多谢。
\n基本思想是用于SpeechRecognizer连接到RecognitionService用户在常规 Android 设置中选择的。
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(context);
sr.setRecognitionListener(new RecognitionListener() {
@Override
public void onResults(Bundle b) { /* ... */ }
// other required methods
});
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "");
sr.startListening(intent);
Run Code Online (Sandbox Code Playgroud)
您必须提供 - 方法的实现RecognitionListener,允许您更新 UI 以响应语音识别事件(用户开始说话、部分结果可用、用户停止说话、转录仍在继续、发生错误等)。
请参阅一些键盘应用程序的源代码中的完整实现,例如Hacker's Keyboard 中的 VoiceInput 类。
| 归档时间: |
|
| 查看次数: |
4888 次 |
| 最近记录: |