document.addEventListener("plusready", function() {
var playStatus = "stop";
document.getElementById("playAutoMsg").addEventListener("tap", function() {
var device = plus.device.model.toLocaleLowerCase();
var nedConts = document.getElementById("itemcontent").innerText;
nedConts = nedConts.replace("·", "");//内容处理
if (nedConts == "") {
mui.alert("没有播放内容", "警告", function() {});
} else {
if ("iphone" == device) {
//iphone
var AVSpeechSynthesizer = plus.ios.importClass("AVSpeechSynthesizer");
var AVSpeechUtterance = plus.ios.importClass("AVSpeechUtterance");
var AVSpeechSynthesisVoice = plus.ios.import("AVSpeechSynthesisVoice");
var sppech = new AVSpeechSynthesizer();
var voice = AVSpeechSynthesisVoice.voiceWithLanguage("zh-CN");
var utterance;
if (playStatus == "stop") {
//点击第一次播放
utterance = AVSpeechUtterance.speechUtteranceWithString(nedConts);
jQuery("#play").attr("src","../images/comm/iconfont-voiceclose-blue.png")
playStatus = "play";
} else {
//再次点击停止播放
utterance = AVSpeechUtterance.speechUtteranceWithString("");
jQuery("#play").attr("src","../images/comm/iconfont-voice-blue.png")
playStatus = "stop";
}
utterance.setVoice(voice);
sppech.speakUtterance(utterance);
plus.ios.deleteObject(voice);
plus.ios.deleteObject(utterance);
plus.ios.deleteObject(sppech);
} else {
//andorid
var main = plus.android.runtimeMainActivity();
var SynthesizerPlayer = plus.android.importClass('com.iflytek.speech.SynthesizerPlayer');
var play = SynthesizerPlayer.createSynthesizerPlayer(main,'appid=Hunanpaile20150728');
play.playText(nedConts,null,null);
}
}
});
}, false);
小琪琪
- 发布:2016-03-02 16:09
- 更新:2018-01-18 08:50
- 阅读:2543
小琪琪 (作者)
谢谢大神,大神那你知道安卓科大讯飞的如何停止、暂停、继续吗?
2016-03-04 09:03