Reputation: 35
I am wondering how do you make an App like Utter or Siri. Not as sophisticated but something that allows me to get vocal input from a user and respond with an updated UI and vocal confirmation. For example : How much did I spend for my phone? The app will answer " the Nexus 5 or the Samsung S4?" (let's say it has a list of all my smartphones) After my answer, it will display the price in the UI with a vocal confirmation.
Now, I have seen that it is possible with Android M but it's going to be a while before the majority of devices update to Android M. And I want a solution that is backward compatible.
Any thoughts of the tools needed ?
Thanks,
Upvotes: 0
Views: 384
Reputation: 1402
There's been an Android API for doing this for a long time. This is old code but I think it should work. It launches the google voice recognition dialog through an intent.
private void startVoiceRecognitionActivity()
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
startActivityForResult(intent, REQUEST_CODE);
}
/**
* Handle the results from the voice recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
{
// Populate the wordsList with the String values the recognition engine thought it heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
matches));
}
super.onActivityResult(requestCode, resultCode, data);
}
Useful links: http://android-developers.blogspot.com.es/2010/03/speech-input-api-for-android.html http://www.jameselsey.co.uk/blogs/techblog/android-how-to-implement-voice-recognition-a-nice-easy-tutorial/
Upvotes: 1