【问题标题】:How can I integrate speech recognition with my camera app?如何将语音识别与我的相机应用程序集成?
【发布时间】:2012-01-01 18:12:22
【问题描述】:

我正在尝试将语音识别集成到我的相机应用程序中,更具体地说,我希望我的相机打开,然后单击“收听”按钮,它会监听“snap”一词,然后拍照。我已经在应用程序上有一个按钮,它只是添加语音部分。你如何让它检查特定的单词?

【问题讨论】:

    标签: android camera speech-recognition voice


    【解决方案1】:

    要在收到用户说出“快照”的信号后实际拍摄照片,您必须实现相机应用的替换。您可以查看相机预览示例应用程序(在 API 演示/图形中)以了解如何显示预览图像。 Camera 类概述包含有关如何实际捕获图像的详细信息。

    【讨论】:

      【解决方案2】:

      这显示了 TTS 和语音识别的完整用法

      https://github.com/gmilette/Say-the-Magic-Word-

      您还需要以下物品:

      一个简单的匹配方法是使用这个循环:

      protected void receiveWhatWasHeard(List<String> heard,
              )
      {
          WordDictionary command = new WordDictionary("Add");
          for (String said : heard)
          {
              if (command.isIn(said.split("\\s")))
              {
                  Log.d(TAG, "heard add");
              }
          }
      }
      

      还有这个类:

      public class WordDictionary
      {
          private Set<String> words;
      
          public WordDictionary(String... wordsIn)
          {
              this(Arrays.asList(wordsIn));
          }
      
          public WordDictionary(List<String> wordsIn)
          {
              words = new LinkedHashSet<String>(wordsIn);
          }
      
          public Set<String> getWords()
          {
              return words;
          }
      
          public boolean isIn(String word)
          {
              return words.contains(word);
          }
      
          public boolean isIn(String [] wordsIn)
          {
              boolean wordIn = false;
              for (String word : wordsIn)
              {
                  if (isIn(word))
                  {
                      wordIn = true;
                      break;
                  }
              }
              return wordIn;
          }
      
      }
      

      你的活动需要这个:

      @Override
          protected void
                  onActivityResult(int requestCode, int resultCode, Intent data)
          {
              if (requestCode == VOICE_RECOGNITION_REQUEST_CODE)
              {
                  if (resultCode == RESULT_OK)
                  {
                      List<String> heard =
                              data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                      for (int i = 0; i < heard.size(); i++)
                      {
                          Log.d(TAG, i + ": " + heard.get(i));
                      }
                      receiveWhatWasHeard(heard);
                  } else
                  {
      //fail
                  }
              }
              super.onActivityResult(requestCode, resultCode, data);
          }
      

      【讨论】:

      • 我尝试导入您在其中的应用程序,但出现错误介意给我帮助吗?
      【解决方案3】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-12
        • 2018-12-21
        • 1970-01-01
        • 1970-01-01
        • 2019-06-19
        • 1970-01-01
        相关资源
        最近更新 更多