Android原生的TTS(语音播报功能)
16lz
2021-12-04
android自带的TTS目前只支持英文、法文、意大利文、德文、西班牙文。不支持中文,需要借助中文TTS引擎的帮助
简单的android原生TTS开发
1.添加权限
2.初始化textToSeepch
TextToSpeech textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status == textToSpeech.SUCCESS) { int result = textToSpeech.setLanguage(Locale.ENGLISH);//设置语言 if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE && result != TextToSpeech.LANG_AVAILABLE) { Toast.makeText(MainActivity.this, "TTS暂时不支持这种语音的朗读!", Toast.LENGTH_SHORT).show(); } } } }); //speech按钮监听事件 speech.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //播放 textToSpeech.speak(input.getText().toString(), TextToSpeech.QUEUE_ADD, null); } });
更多相关文章
- Android(安卓)中文 API (102)—— CursorAdapter
- Android(安卓)3.0 r1 API中文文档(108) —— ExpandableListAdap
- Android(安卓)中文API (66) ―― BluetoothClass.Device
- android 中文 api (71) ―― BluetoothServerSocket[蓝牙]
- android开发必看资源URL
- Android2.2 API 中文文档系列(4) —— Manifest
- Android(安卓)Fresco属性大全,中文说明
- Android(安卓)中文 API 文档 (44) ―― Chronometer.OnChronometer
- Android中文 API (31) —— TimePicker