1.首先去讯飞语记官网下载并安装APP:
2.设置语音引擎:
设置==>语言和输入法==>文字转语音(TTS)输出==>首选引擎
3.在代码中使用:
import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import java.util.Locale;
public class SystemTTS {
private static final String TAG = "SystemTTS";
private static SystemTTS instance;
private TextToSpeech textToSpeech;
private boolean isSupport = true;
private SystemTTS(Context context) {
textToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.CHINA);
textToSpeech.setPitch(1.0f); // 设置音调