我想使用RecognizerIntent和默认的android Wear UI来实现关键词语音识别。
问题是我无法更改android Wear手表正在收听的默认语言。由于识别错误,我只想识别英语单词,我不想更改手机的默认语言。我正在做这样的事情:
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_LANGUAGE, "en-US");
startActivityForResult(intent, SPEECH_REQUEST_CODE);
}
@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);
mTextView.setText(spokenText);
if (spokenText.contains("KeyWord")) {
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
long[] vibrationPattern = {0, 500, 50, 300};
//-1 - don't repeat
final int indexInPatternToRepeat = -1;
vibrator.vibrate(vibrationPattern, indexInPatternToRepeat);
}
// Do something with spokenText
}
super.onActivityResult(requestCode, resultCode, data);
}
此解决方案有效,但也没有给我英文结果。 语音识别由android Wear watch完成。
答案 0 :(得分:-1)
很抱歉,但我没有使用RecognizerIntent
,所以我可以给出一个建议可能就是可以做到这一点。
但是,您无法切换正在进行的识别语言。
启动Google搜索应用。转到
设置 - 语言并检查那里的西班牙语和英语。之后用西班牙语进行TAP AND HOLD,然后保存。
您也可以尝试使用es或fr标签,就像您使用en-US
英语一样,它也可以使用。
但是你应该使用en_US
代替en-US
。
这将强制您的Android设备默认识别西班牙语。 为了更好地理解,您可以看到Android开发者网站: http://developer.android.com/reference/android/speech/RecognizerIntent.html#EXTRA_LANGUAGE