赞
踩
登录讯飞语音平台,创建一个应用,并领取免费的在线语音合成,总的可以领取到55万条,有效期一年
然后下载SDK放到lib下
implementation files('libs/Msc.jar')
import android.os.Bundle; import com.iflytek.cloud.SpeechConstant; import com.iflytek.cloud.SpeechError; import com.iflytek.cloud.SpeechSynthesizer; import com.iflytek.cloud.SpeechUtility; import com.iflytek.cloud.SynthesizerListener; import com.zhhy.qneatrice.app.cashier.MainActivity; /** * 讯飞语音 * * @author Tellsea * @date 2021-10-18 */ public class MscUtils { public static void initIflytek() { SpeechUtility.createUtility(MainActivity.CONTEXT, SpeechConstant.APPID + "=应用APPID"); } public static void speekText(String text) { //1. 创建 SpeechSynthesizer 对象 , 第二个参数: 本地合成时传 InitListener SpeechSynthesizer mTts = SpeechSynthesizer.createSynthesizer(MainActivity.CONTEXT, null); //2.合成参数设置,详见《 MSC Reference Manual》 SpeechSynthesizer 类 //设置发音人(更多在线发音人,用户可参见 附录 13.2 mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan"); // 设置发音人 mTts.setParameter(SpeechConstant.SPEED, "50");// 设置语速 mTts.setParameter(SpeechConstant.VOLUME, "100");// 设置音量,范围 0~100 mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD); //设置云端 //3.开始合成 mTts.startSpeaking(text, new MySynthesizerListener()); } static class MySynthesizerListener implements SynthesizerListener { @Override public void onSpeakBegin() { } @Override public void onSpeakPaused() { } @Override public void onSpeakResumed() { } @Override public void onBufferProgress(int percent, int beginPos, int endPos, String info) { // 合成进度 } @Override public void onSpeakProgress(int percent, int beginPos, int endPos) { // 播放进度 } @Override public void onCompleted(SpeechError error) { } @Override public void onEvent(int eventType, int arg1, int arg2, Bundle obj) { } } }
// 初始化讯飞
MscUtils.initIflytek();
MscUtils.speekText("识别失败,正在重试");
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。