分享

android

 點點滴滴 2011-12-13
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

Refer http://developer./resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html It shows how to add Voice Recognition to your app. http://developer./reference/android/speech/package-summary.html This package is useful for a reference too.

link|improve this answer

feedback

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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多