Running Android Text to Speech on android wear?

2019-08-03 18:54发布

问题:

Is it possible to run Text to Speech API on android wear devices? I am trying to do that but it is not working.

The watch will display list of cards containing words and and there will be a button when clicked the user can hear the word in the current card.

I got it working on a mobile phone but my objective is to make it work on android watch.

Any help is appreciated. Thanks.

回答1:

If you wanna to use Voice commands for your wearable device you can use this implementation:

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);
// 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);
        // Do something with spokenText
    }
    super.onActivityResult(requestCode, resultCode, data);
}

https://developer.android.com/training/wearables/apps/voice.html



回答2:

Android Wear 2.0 has this built in - under Settings -Accessibility- Text to Speech Output. So if you don't currently have a Huawei or Urbane 2 the main release is rumored in just a few weeks on Feb 9/10th.