【问题标题】:Speech Recognizer Android integrate with camera语音识别器 Android 与相机集成
【发布时间】:2016-05-16 11:20:00
【问题描述】:

我正在创建一个相机应用程序,它会在用户说“自拍”时捕捉图像。任何人都请帮忙,因为我不知道如何使用语音识别器。如果您能分享代码,那将非常有帮助。

我有一个想法,但我不知道如何整合它:

1- 语音识别器接受用户的输入。

2- 将其与“自拍”进行比较,如果匹配捕获图片,则使用 IF 语句,如果不吐司再说一遍。

【问题讨论】:

    标签: android android-camera speech-recognition


    【解决方案1】:

    这样试试

                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);    
                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
                intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1); 
    startActivityForResult(intent,requestcode);
    

    然后重写 OnActivityResult() 方法,如果与自拍比较匹配则调用 Camera Intent

     @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==101) {
         ArrayList<String> matches_text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    if(matches_text.get(0).equals("selfie"))
    {
    
    Intent cam=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cam,requestcode);
    }
    
    else
     {
     Toast.makeText(getApplicationContext(),"Please try again",LENGTH_LONG).show()
     }
    

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 2019-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多