美文网首页Android广场
编写使用Android 系统自带的文字转语音代码

编写使用Android 系统自带的文字转语音代码

作者: Visen遥清风 | 来源:发表于2020-08-18 01:55 被阅读0次

调用Android系统语音TextToSpeech实例对象

具体代码写法如下:

TextToSpeech mTextToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {

@Override

public void onInit(int status) {

if (status==TextToSpeech.SUCCESS) {

//设置语言朗读

int supported= mTextToSpeech.setLanguage(Locale.US);

if ((supported!=TextToSpeech.LANG_AVAILABLE)&& (supported!=TextToSpeech.LANG_COUNTRY_AVAILABLE)) {

Toast.makeText(this, "不支持当前语言!", Toast.LENGTH_SHORT).show();

}

}

}

});

mTextToSpeech.speak("这里填入想要转成语音的文字", TextToSpeech.QUEUE_FLUSH, null);

相关文章

网友评论

    本文标题:编写使用Android 系统自带的文字转语音代码

    本文链接:https://www.haomeiwen.com/subject/fvaqjktx.html