Android原生的TTS(语音播报功能)
16lz
2021-01-23
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 3.0 r1 API中文文档(108) —— ExpandableListAdapter
- Android 中文API (66) ―― BluetoothClass.Device
- android 中文 api (71) ―― BluetoothServerSocket[蓝牙]
- Android2.2 API 中文文档系列(4) —— Manifest
- Android 中文 API 文档 (44) ―― Chronometer.OnChronometerTickL
- Android中文 API (31) —— TimePicker
- android 2.3 r1 中文 api (58) —— TabHost
- Android 利用Java实现压缩与解压缩(zip、gzip)支持中文路径