2

我想使用 RecognizerIntent 和默认的 android wear UI 来实现关键词语音识别。

问题是我无法更改 android wear watch 监听的默认语言。由于识别错误,我只想识别英文单词,我不想更改手机的默认语言。我正在做这样的事情:

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 完成。

4

1 回答 1

-1

对不起,但我没有用RecognizerIntent太多,所以我只能给出一个建议,也许它可以解决问题。

但是,您不能在进行中切换识别语言。启动谷歌搜索应用。转到
设置-语言并在那里检查西班牙语和英语。之后点击并按住西班牙语,然后保存。

您也可以尝试使用 es 或 fr 标签,就像您在en-US英语中使用的那样,它也可以工作。
但是你应该使用en_US而不是en-US.

这将强制您的 Android 设备默认识别西班牙语。为了更好地理解,您可以查看 Android 开发者网站:http: //developer.android.com/reference/android/speech/RecognizerIntent.html#EXTRA_LANGUAGE



另请参阅此问题:https ://stackoverflow.com/a/10548680/3950422

于 2015-04-22T08:18:23.500 回答