小米最新开发版版本号:android
来源:百度文库 编辑:偶看新闻 时间:2024/04/26 14:23:12
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?
android camera speech-recognition voice link|improve this question asked Nov 19 at 3:12tjr2010704
44% accept rate
feedback
3 Answers
activeoldestvotes up vote 0 down voteRefer http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.htmlIt shows how to add Voice Recognition to your app.http://developer.android.com/reference/android/speech/package-summary.htmlThis package is useful for a reference too.
link|improve this answer answered Nov 19 at 3:16om252345658411
feedback up vote 0 down vote
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 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 words;
public WordDictionary(String... wordsIn)
{
this(Arrays.asList(wordsIn));
}
public WordDictionary(List wordsIn)
{
words = new LinkedHashSet(wordsIn);
}
public Set 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 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 answered Nov 19 at 14:37gregm1,0571923
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? up vote 0 down vote
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 answered Nov 19 at 17:54jonawebb1
feedback