Google 文字转语音 api setVoice() 不可用

Google text to speech api setVoice() not available

文档 https://developer.android.com/reference/android/speech/tts/TextToSpeech.html 有一个方法 setVoice() ,我们可以在其中设置语音对象。

但是当我在我的应用程序中创建一个 TextToSpeech 对象时,我没有得到方法 setVoice() 。

TextToSpeech tts = tts = new TextToSpeech(this, this);
int result = tts.setLanguage(Locale.US); // I get this method
int result1 = tts.setVoice(); // I dont get this method.

setLanguage 已添加到 API 级别 4,但 setVoice 已添加到 API 级别 21。确保您使用的是 API 21 级或以上才能使用 setVoice.