繁体   English   中英

Android中的语音识别无法正常工作

[英]speech recognition in android not working

我正在尝试创建一个应用程序,当电话打来时,呼叫必须根据用户语音命令自动出席或结束。 在这里我给了我尝试的东西,我在startVoiceRecognitionActivity()方法中遇到错误,例如Activity找不到异常:找不到活动来处理意图。

   public void startVoiceRecognitionActivity()
{
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
    startActivityForResult(intent, REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub

    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    {
        String spch = data.getStringExtra(RecognizerIntent.EXTRA_RESULTS);


        if (spch.contains("Yes"))    
         {
            enableSpeakerPhone(this);

            Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
            KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK);
            i.putExtra(Intent.EXTRA_KEY_EVENT, event );
            this.sendOrderedBroadcast(i, null);
         }
         else if(spch.contains("No"))
         {
            Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON); 
            buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
            this.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
         }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

谁能帮我找出问题所在...

您是否在清单文件中正确声明了活动?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM