语音命令将无法打开活动

时间:2019-06-01 02:23:48

标签: android speech-recognition

我已经尝试了一个语音控制的应用程序,经过许多示例等,我有以下代码。

        FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new  Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
            intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
            mySpeechRecognizer.startListening(intent);
            speak("I wait for your instuctions");
        }
    });

                @Override
            public void onResults(Bundle bundle) {
                List<String> results = bundle.getStringArrayList(
                        SpeechRecognizer.RESULTS_RECOGNITION
                );
                processResult(results.get(0));


            }

    private void processResult(String mycom){
    mycom = mycom.toLowerCase();

    if(mycom.contains("one")) {
        speak("Opening one");
        Intent intent = new Intent(MainActivity.this, OneActivity.class);
        startActivity(intent);

该应用程序会构建并运行,并显示“我正在等待您的指示”,但在用户指示后不会打开新活动。

有人可以帮助我了解错误之处吗

0 个答案:

没有答案