打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
android
How can I integrate speech recognition with my camera app?

I am trying to integrate speech recognition to my camera app, more specifically I want my camera to open up and you click a button "Listen" and it listens for the word "snap" and then it takes a picture. I have a button on the app already, it is just adding the voice portion to it. How do you get it to check for specfic words?

link|improve this question

44% accept rate

feedback

3 Answers

This shows a complete usage of TTS and Speech Recognition

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

Also you need the following:

A simple way to match is to use this loop:

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");
       
}
   
}
}

and this class:

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;
   
}

}

And your activity needs this:

@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);
   
}
link|improve this answer


i tried to import the app you had inside and I got errors mind giving me help? – tjr2010 Nov 20 at 6:26

which app and what errors? – gregm Nov 23 at 19:30
Was this post useful to you?     

To actually take the photo once you get the signal that the user has said 'Snap' you have to implement a replacement for the Camera app. You can look at the Camera preview sample app (in API Demos / graphics) to see how to show the preview image. And the Camera class overview has detailed information on how to actually capture the image.

link|improve this answer

feedback

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android微信支付
移动端app 文档交接模版
C#读取Word文档内容 | 胡航飞博客
微软在移动市场的另一种成功:Android版Word已超10亿次装机量
Android 双进程守护尝试与分析
android改变应用程序图标的方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服