Karol Żygłowicz
Karol Żygłowicz

Reputation: 2452

How to change speech recognition language in Android wear

I want to implement key word speech recognition using RecognizerIntent and default android wear UI.

The problem is I'm not able to change the default language in which the android wear watch is listening. I want to recognise only English words due to recognition errors and I don't want to change phone's default language. I'm doing something like this:

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);
}

This solution works but gives me not English result too. The speech recognition is done by android wear watch.

Upvotes: 2

Views: 2028

Answers (1)

bhansa
bhansa

Reputation: 7504

Sorry but I haven't used RecognizerIntent much so I can just give a suggestion may be it can do the trick.

BUT, you can't switch recognition language in progress. Launch Google search app. Go to
settings-Languages and check Spanish and English languages there. after that TAP AND HOLD on Spanish language and then Save.

You can also try with es or fr tags like you have used en-USfor English, it can also work.
But you should use en_US instead of en-US.

This will force your android device to recognize Spanish language by default. For better understanding you can see Android Developer site : http://developer.android.com/reference/android/speech/RecognizerIntent.html#EXTRA_LANGUAGE



Also see this question :https://stackoverflow.com/a/10548680/3950422

Upvotes: -1

Related Questions