XunfeiSpeek 讯飞语言合成工具类

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;


import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechSynthesizer;
import com.iflytek.cloud.SynthesizerListener;


/**
 * Created by Administrator on 2016/9/15.
 */
public class XunfeiSpeek {
    private SpeechSynthesizer mTts;
    private String speakControl = "80";
    private String peopleControl = "xiaoyu";


    public XunfeiSpeek(Context context) {

        SpeechUtility.createUtility(context, SpeechConstant.APPID + "=你自己的appid");

        mTts = SpeechSynthesizer.createSynthesizer(context, null);
        SharedPreferences sp = context.getSharedPreferences("config", context.MODE_PRIVATE);
        peopleControl = sp.getString("peopleControl", "xiaoyu");
        speakControl = sp.getString("speakControl", "80");
    }


    public void init(){

        //2.合成参数设置,详见《MSC Reference Manual》SpeechSynthesizer 类
        //设置发音人(更多在线发音人,用户可参见 附录13.2
        mTts.setParameter(SpeechConstant.VOICE_NAME, peopleControl); //设置发音人
        mTts.setParameter(SpeechConstant.SPEED, speakControl);//设置语速


        mTts.setParameter(SpeechConstant.VOLUME, "80");//设置音量,范围 0~100
        mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD); //设置云端
        //设置合成音频保存位置(可自定义保存位置),保存在“./sdcard/iflytek.pcm”
        //保存在 SD 卡需要在 AndroidManifest.xml 添加写 SD 卡权限
        //仅支持保存为 pcm 和 wav 格式,如果不需要保存合成音频,注释该行代码


        mTts.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");


        String formatTime1 = new TimeFormat().getTime();
        mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, Environment.getExternalStorageDirectory() + "/com.jinjie/" + formatTime1 + ".wav");


    }


    public void destory(){
//        mTts.stopSpeaking();
        mTts.destroy();
    }


    public void speeking(String text, SynthesizerListener mSynListener){
        mTts.startSpeaking(text, mSynListener);
    }


    public void download(String text, SynthesizerListener mSynListener){
        String formatTime = new TimeFormat().getTime();
        mTts.synthesizeToUri(text, Environment.getExternalStorageDirectory() + "/com.jinjie/" + formatTime + ".wav", mSynListener);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值