Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android语音识别/听写_Java_Android_Speech Recognition - Fatal编程技术网

Java Android语音识别/听写

Java Android语音识别/听写,java,android,speech-recognition,Java,Android,Speech Recognition,你好 我正处于构建烹饪/食谱应用程序的早期阶段。该应用程序的主要目的是能够通过语音听写遵循和遍历食谱。有人能给我指出如何实现这些功能的正确方向吗 谢谢 调用系统的内置语音识别器活动,从用户处获取语音输入。这有助于从用户处获取输入,然后对其进行处理,例如进行搜索或将其作为消息发送 在应用程序中,您可以使用ACTION\u Recognite\u SPEECH操作调用startActivityForResult()。这将启动语音识别活动,然后可以在onActivityResult()中处理结果 pr

你好

我正处于构建烹饪/食谱应用程序的早期阶段。该应用程序的主要目的是能够通过语音听写遵循和遍历食谱。有人能给我指出如何实现这些功能的正确方向吗


谢谢

调用系统的内置语音识别器活动,从用户处获取语音输入。这有助于从用户处获取输入,然后对其进行处理,例如进行搜索或将其作为消息发送

在应用程序中,您可以使用ACTION\u Recognite\u SPEECH操作调用startActivityForResult()。这将启动语音识别活动,然后可以在onActivityResult()中处理结果

private static final int SPEECH\u REQUEST\u code=0;
//创建可以启动语音识别器活动的意图
私有void displaySpeechRecognizer(){
意向意向=新意向(识别意向、行动、识别言语);
intent.putExtra(识别器intent.EXTRA_语言_模型,
识别者意图、语言、模型、自由形式);
//开始活动时,将用语音文本填充意图
startActivityForResult(意图、言语请求代码);
}
//语音识别器返回时调用此回调。
//这是您处理意图并从意图中提取语音文本的地方。
@凌驾
ActivityResult上受保护的void(int请求代码、int结果代码、,
意图(数据){
if(requestCode==SPEECH\u REQUEST\u CODE&&resultCode==RESULT\u OK){
列表结果=data.getStringArrayListExtra(
识别者意图。额外结果);
字符串spokenText=results.get(0);
//用spokenText做点什么
}
super.onActivityResult(请求代码、结果代码、数据);
}
private static final int SPEECH_REQUEST_CODE = 0;

// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// Start the activity, the intent will be populated with the speech text
    startActivityForResult(intent, SPEECH_REQUEST_CODE);
}

// This callback is invoked when the Speech Recognizer returns.
// This is where you process the intent and extract the speech text from the intent.
@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent data) {
    if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
        List<String> results = data.getStringArrayListExtra(
                RecognizerIntent.EXTRA_RESULTS);
        String spokenText = results.get(0);
        // Do something with spokenText
    }
    super.onActivityResult(requestCode, resultCode, data);
}