开发过程中有时需要用到科大讯飞的SDK,下面是我自己写的文字转语音的工具类:
package utils;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechSynthesizer;
import com.iflytek.cloud.SynthesizerListener;
public class SpeechUiUtils {
//传入上下文,和需要转成语音的文字
public static void read(Context context, String read) {
SpeechSynthesizer mTts = SpeechSynthesizer.createSynthesizer(context,
null);
mTts.setParameter(SpeechConstant.VOICE_NAME, “aisxping”);
mTts.setParameter(SpeechConstant.SPEED, “50”);
mTts.setParameter(SpeechConstant.VOLUME, “100”);
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);// 设置云端
mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, “./sdcard/iflytek.pcm”);// 语音保存位置
mTts.startSpeaking(read, mSynListener);
}
//传入上下文,和需要转成语音的文字,voi