HBuilder版本号为7.6.3.201612161809及之后的用户请用如下Native.Js代码实现:
var receiver;
receiver = plus.android.implements('com.iflytek.cloud.SynthesizerListener', {
onEvent: function(int eventType, int arg1, int arg2, Bundle obj) {
console.log("onEvent");
},
onSpeakBegin: function() {
console.log("开始阅读");
},
onSpeakPaused: function() {
console.log(" 暂停播放 ");
},
onSpeakResumed: function() {
console.log("继续播放");
},
onBufferProgress: function(percent, beginPos, endPos, info) {
console.log("合成进度" + percent);
},
onSpeakProgress: function(percent, beginPos, endPos) {
console.log("播放进度" + percent);
},
onCompleted: function(error) {
console.log("播放完毕");
}
});
var main = plus.android.runtimeMainActivity();
var SpeechUtility = plus.android.importClass('com.iflytek.cloud.SpeechUtility');
SpeechUtility.createUtility(main, "appid=53feacdd");
var SynthesizerPlayer = plus.android.importClass('com.iflytek.cloud.SpeechSynthesizer');
var play = SynthesizerPlayer.createSynthesizer(main, null);
// 开始合成
play.startSpeaking('新年快乐', receiver);
// 取消合成
play.stopSpeaking();
// 暂停播放
play.pauseSpeaking();
// 继续播放
play.resumeSpeaking();
该版本之前的用户请参考下面的写法:
由于Android系统tts不支持中文,使用科大讯飞文字转语音功能,使用如此功能时,需要保证manifest.json中permissions节点含有speech节点(如"Speech": {"description": "管理语音识别插件" })。
var main = plus.android.runtimeMainActivity();
var SynthesizerPlayer = plus.android.importClass('com.iflytek.speech.SynthesizerPlayer');
var play = SynthesizerPlayer.createSynthesizerPlayer(main,'appid=53feacdd');
play.playText('水果',null,null);
iOS平台参考[http://ask.dcloud.net.cn/question/4175)(http://ask.dcloud.net.cn/question/4175)
45 个评论
要回复文章请先登录或注册
y***@outlook.com
2***@qq.com
9***@qq.com
by_dc
5***@qq.com
5***@qq.com
8***@qq.com
8***@qq.com
z***@163.com
2***@qq.com