【发布时间】:2017-01-20 11:41:24
【问题描述】:
目前我有语音识别功能,但RecognizerIntent.EXTRA_PROMPT 仅在移动设备和可穿戴手表上显示为文本。
是否有任何方法或其他选项可以提示说话(作为音频播放)?
已经尝试过VoiceInteraction API,但它仅限于选择一个选项,并且必须通过系统语音命令之一启动。
private static final int SPEECH_REQUEST_CODE = 0;
// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "How can I help you?");
// Start the activity, the intent will be populated with the speech text
startActivityForResult(intent, SPEECH_REQUEST_CODE);
}
// This callback is invoked when the Speech Recognizer returns.
// This is where you process the intent and extract the speech text from the intent.
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
List<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
Log.d(TAG, "spokenText: " + spokenText);
// Do something with spokenText
}
super.onActivityResult(requestCode, resultCode, data);
}
【问题讨论】:
标签: android wear-os voice-recognition voice-interaction