语音合成约定

TTS分两类:talkback、msc;系统默认安装语记,talkback会使用设置的TTS引擎,同时对于需要回掉的场景提供msc封装。

1.talkback

talkback进行界面上的播报及所有语音信息的播报(先前用net.tatans.coeus.util下的播报统一改成net.tatans.coeus.network 下的TatansToast)

注意点

播报Toast信息由于会被打断,因此建议仅用一些提示,根据场景,调不同处理方法

后面一个Toast播报会打断前面一个:TatansToast.showAndCancel(String )

播报完成后播:连续调用TatansToast.showShort(String s)

2.msc

TatansSpeaker有两种使用方法,一种是全局使用的Speaker,一种是单个类里面使用的Speaker;但是两种方法都必须在gradle中添加以下代码
configurations.all {
resolutionStrategy.cacheChangingModulesFor 1, ‘minutes’
}
dependencies {
compile ‘net.tatans.coeus:coeus-network:5.4.0-SNAPSHOT’
}

TatansSpeaker全局的使用方法(推荐使用)
首先要在Application中的onCreate()方法中调用setAppSpeaker();——-这个是必须的。
然后在单个的Class中就可以调用了。
例如:
/**
* 全局speak示例
* Created by Administrator on 2016/4/22.
*/
public class GlobalActivity extends TatansActivity {
@ViewInject(id = R.id.tts_play, click = “btnPlay”)
TextView tts_play;
@ViewInject(id = R.id.tts_cancel, click = “btnCancel”)
TextView tts_cancel;
@ViewInject(id = R.id.tts_pause, click = “btnPause”)
TextView tts_pause;
@ViewInject(id = R.id.tts_resume, click = “btnResume”)
TextView tts_resume;
@ViewInject(id = R.id.tts_text)
TextView tts_text;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ttsdemo);
}

//    播放
public void btnPlay(View view) {
    TatansApplication.speech(tts_text.getText().toString(), 88, new TatansSpeakerCallback() {

        @Override
        public void onSpeakBegin() {
            super.onSpeakBegin();//开始
        }

        @Override
        public void onSpeakPaused() {
            super.onSpeakPaused();//暂停
        }
        @Override
        public void onSpeakResumed() {
            super.onSpeakResumed();//继续
        }

        @Override
        public void onSpeakProgress(int percent, int beginPos, int endPos) {
            super.onSpeakProgress(percent, beginPos, endPos); //percent 播放进度 beginPos 开始播放 endPos 停止播放
        }

        @Override
        public void onCompleted() {
            super.onCompleted();//播放完成
        }

        @Override
        public void onCompletedError() {
            super.onCompletedError();
        }
    });
}

//    结束
public void btnCancel(View view) {
    TatansApplication.stop();
}

//    暂停
public void btnPause(View view) {
    TatansApplication.pause();
}

//    继续
public void btnResume(View view) {
    TatansApplication.resume();
}

TatansSpeaker在单个Class中的使用方法
首先要在Class中的定义一个TatansSpeaker ;
其次在onCreate()中调用TatansSpeaker.create();——-这个是必须的;
然后在Class中就可以调用了;
最后记得在onDestroy()方法中将其销毁。
例如:
/**
* 单个class的speak示例
* Created by Administrator on 2016/4/25.
*/
public class SingleActivity extends TatansActivity {
@ViewInject(id = R.id.tts_play, click = “btnPlay”)
TextView tts_play;
@ViewInject(id = R.id.tts_cancel, click = “btnCancel”)
TextView tts_cancel;
@ViewInject(id = R.id.tts_pause, click = “btnPause”)
TextView tts_pause;
@ViewInject(id = R.id.tts_resume, click = “btnResume”)
TextView tts_resume;
@ViewInject(id = R.id.tts_text)
TextView tts_text;
private TatansSpeaker speaker;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ttsdemo);
    speaker = TatansSpeaker.create();// 单个class的speak需要的
}

//    播放
public void btnPlay(View view) {

    speaker.speech(tts_text.getText().toString(), 88);
}

//    结束
public void btnCancel(View view) {
    speaker.stop();
}

//    暂停
public void btnPause(View view) {
    speaker.pause();
}

//    继续
public void btnResume(View view) {
    speaker.resume();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    speaker.destroy();
}

}

注意点
TatansSpeaker的speech(String str,int speed,TatansSpeakerCallback speakerCallback)方法是非常重要的。其中的前两个参数分别是:播报内容,播报速度。第三个当new TatansSpeakerCallback()后,需要注意的如下:
@Override
public void onSpeakBegin() {
super.onSpeakBegin();//开始
}

        @Override
        public void onSpeakPaused() {
            super.onSpeakPaused();//暂停
        }
        @Override
        public void onSpeakResumed() {
            super.onSpeakResumed();//继续
        }

        @Override
        public void onSpeakProgress(int percent, int beginPos, int endPos) {
            super.onSpeakProgress(percent, beginPos, endPos); //percent 播放进度 beginPos 开始播放 endPos 停止播放
        }

        @Override
        public void onCompleted() {
            super.onCompleted();//播放完成
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值