在android上运行Android Text to Speech?

时间:2017-01-22 08:08:46

标签: android wear-os

是否可以在Android服装设备上运行Text to Speech API?我试图这样做,但它没有用。

手表将显示包含单词的卡片列表,单击时会有一个按钮,用户可以听到当前卡片中的单词。

我让它在手机上工作,但我的目标是让它在Android手表上运行。

感谢任何帮助。 感谢。

2 个答案:

答案 0 :(得分:1)

如果您想为可穿戴设备使用语音命令,可以使用此实现:

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

答案 1 :(得分:1)

Android Wear 2.0内置了 - 在设置 - 可访问性 - 文本到语音输出下。因此,如果您目前没有华为或Urbane 2,那么主要版本将在2月9日的几周内传播。