有没有办法立即向Google发送字符串并获得回复?
示例:
发送“几点了?”并从谷歌获得一个字符串或音频回复,说“这是下午4:32。”
String question = "What time is it?";
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(question);
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String converted_text = result.get(0);
}
break;
}
}
}
答案 0 :(得分:0)
您应该自己分析问题并获得答案并使用TextToSpeech将其发回。对于您的示例:您分析了您找到“时间”的字符串,并从Android系统获得时间,并将时间作为字符串发送回TextToSpeech。