2017-01-22 62 views
1

是否可以在Android Wear設備上運行文本到語音API?我正在嘗試這樣做,但它不起作用。在Android Wear上運行Android Text to Speech?

手錶將顯示包含單詞的卡片列表,單擊時會出現一個按鈕,用戶可以聽到當前卡片中的單詞。

我得到它在手機上工作,但我的目標是使它在Android手錶上工作。

任何幫助表示讚賞。 謝謝。

回答

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

+0

我希望它讀取卡片中的文本而不是語音命令。我已經添加了更多的細節問題。 –

1

用於Android Wear 2.0這個建於 - 在設置下-Accessibility-文本到語音輸出。所以,如果你目前沒有華爲或Urbane 2,那麼在2月9日和10日的短短几周內就會發布主要版本。