现在有没有办法向谷歌发送一个字符串并得到回复?
例子:
发送“现在几点?” 并从谷歌获得一个字符串或音频响应,上面写着“现在是下午 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;
}
}
}