语音交互应用[Android]

时间:2015-06-23 09:01:31

标签: android speech-recognition text-to-speech voice-recognition speech

我想知道你如何制作像Utter或Siri这样的应用程序。不那么复杂,但允许我从用户获得声音输入并使用更新的UI和声音确认进行响应。 例如:我花了多少钱购买手机? 该应用程序将回答" Nexus 5还是三星S4?" (让我们说它有我所有智能手机的清单) 在我的回答之后,它会在用户界面中显示价格并发出声音确认。

现在,我已经看到Android M可以实现,但在大多数设备更新到Android M之前还需要一段时间。我想要一个向后兼容的解决方案。

对所需工具的想法是什么?

谢谢,

1 个答案:

答案 0 :(得分:1)

很长一段时间以来,都有一个Android API。这是旧代码,但我认为它应该工作。它通过意图启动谷歌语音识别对话框。

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

有用的链接: 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/

相关问题