Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
Created April 14, 2015 09:49
Show Gist options
  • Save ishitcno1/1d8f70cef7aadcdd82cc to your computer and use it in GitHub Desktop.
Save ishitcno1/1d8f70cef7aadcdd82cc to your computer and use it in GitHub Desktop.
讯飞语音 android
public class IFlyHelper {
private static IFlyHelper instance;
// 语音合成对象
private SpeechSynthesizer mTts;
private IFlyHelper(Context context) {
super();
// 初始化合成对象
mTts = SpeechSynthesizer.createSynthesizer(context, null);
// 设置参数
setParam();
}
public static IFlyHelper getInstance(Context context) {
if (instance == null) {
instance = new IFlyHelper(context);
}
return instance;
}
public int notifyNewMsg(String msg) {
return mTts.startSpeaking(msg, null);
}
/**
* 参数设置
*/
private void setParam() {
// 清空参数
mTts.setParameter(SpeechConstant.PARAMS, null);
//设置合成
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
//设置发音人
mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan");
//设置语速
mTts.setParameter(SpeechConstant.SPEED, "50");
//设置音调
mTts.setParameter(SpeechConstant.PITCH, "50");
//设置音量
mTts.setParameter(SpeechConstant.VOLUME, "50");
//设置播放器音频流类型
mTts.setParameter(SpeechConstant.STREAM_TYPE, "3");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment