2017-03-02 140 views
0

文档https://developer.android.com/reference/android/speech/tts/TextToSpeech.html有一个方法setVoice(),我们可以在其中设置语音对象。谷歌文本到语音api 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. 
+0

您使用的是什么API级别? – Ash

回答

2

setLanguage API等级加4,但setVoice API级别21.加入确保您使用的API等级21以上才能使用setVoice

+0

我可以在API中设置自定义语音吗?为什么使用setVoice()? –

+0

无论您的手机的文本到语音引擎中有什么语音,都可以对其进行设置。首先,您需要使用getVoices获取所有可用语音,然后使用setVoice从列表中设置语音。检查getVoices文档 - https://developer.android.com/reference/android/speech/tts/TextToSpeech.html#getVoices() – Ash

+0

如果您需要一些不同于您的Android默认文本语音提供的语音引擎,还有其他第三方API – Ash