语音播报 android,Android 语音播报 文字转语音
发布日期:2022-02-03 04:38:39 浏览次数:10 分类:技术文章

本文共 1412 字,大约阅读时间需要 4 分钟。

最近收到了结合推送 到的内容 语音播报功能实现

就想到sdk内置

android.speech 已经内置了语音播放功能

开始放代码

//创建自带语音对象

private TextToSpeech textToSpeech = null;

/**

* 初始化TextToSpeech对象

*/

private void initTTS() {

//实例化自带语音对象

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

@Override

public void onInit(int status) {

if (status == 0) {

// Toast.makeText(MainActivity.this,"成功输出语音",

// Toast.LENGTH_SHORT).show();

// Locale loc1=new Locale("us");

// Locale loc2=new Locale("china");

textToSpeech.setPitch(1.0f);//方法用来控制音调

textToSpeech.setSpeechRate(1.0f);//用来控制语速

//判断是否支持下面两种语言

int result1 = textToSpeech.setLanguage(Locale.US);

int result2 = textToSpeech.setLanguage(Locale.

SIMPLIFIED_CHINESE);

boolean a = (result1 == TextToSpeech.LANG_MISSING_DATA || result1 == TextToSpeech.LANG_NOT_SUPPORTED);

boolean b = (result2 == TextToSpeech.LANG_MISSING_DATA || result2 == TextToSpeech.LANG_NOT_SUPPORTED);

Log.i("zhh_tts", "US支持否?--》" + a +

"\nzh-CN支持否》--》" + b);

} else {

Toast.makeText(MainActivity.this, "数据丢失或不支持", Toast.LENGTH_SHORT).show();

}

}

});

}

开启播报:

textToSpeech.setLanguage(Locale.JAPANESE);

//设置音调,值越大声音越尖(女生),值越小则变成男声,1.0是常规

textToSpeech.setPitch(4f);

//设置语速

textToSpeech.setSpeechRate(3f);

//输入中文,若不支持的设备则不会读出来

textToSpeech.speak(“要播的内容文本”,

TextToSpeech.QUEUE_FLUSH, null);

使用Android/sdk/sources/android-28/speech/tts/TextToSpech实现语音播报功能就这些了 祝君好运

本文地址:https://blog.csdn.net/weixin_40611659/article/details/110528886

转载地址:https://blog.csdn.net/weixin_30596151/article/details/117569797 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:zend 插件 html5,html - Zend HTML5 Form element types - Stack Overflow
下一篇:android textview unicode,在TextView中显示所有Unicode字符

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月05日 00时40分48秒