Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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
如何在android应用程序中添加语音识别。。并使用切换按钮通过它_Android_Voice Recognition_Togglebutton - Fatal编程技术网

如何在android应用程序中添加语音识别。。并使用切换按钮通过它

如何在android应用程序中添加语音识别。。并使用切换按钮通过它,android,voice-recognition,togglebutton,Android,Voice Recognition,Togglebutton,我的应用程序中有一些切换按钮,我需要将它们与语音命令一起使用。例如,如果说开关1打开,则应打开开关,如果说开关1关闭,则应关闭。。对此感到非常无助,感谢您的帮助,我事先没有任何线索,所以请尝试详细解释每件事这是我从开发者网站获取的使用语音识别的代码 private static final int SPEECH_REQUEST_CODE = 0; // Create an intent that can start the Speech Recognizer activity private

我的应用程序中有一些切换按钮,我需要将它们与语音命令一起使用。例如,如果说开关1打开,则应打开开关,如果说开关1关闭,则应关闭。。对此感到非常无助,感谢您的帮助,我事先没有任何线索,所以请尝试详细解释每件事这是我从开发者网站获取的使用语音识别的代码

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);
}
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(请求代码、结果代码、数据);
}

可能重复无需问两次相同的问题这是关于如何添加语音识别的问题,然后我发现,但不知道如何通过它触发按钮,所以第二个问题就是为了这个