小琪琪
小琪琪
  • 发布:2016-03-02 16:09
  • 更新:2018-01-18 08:50
  • 阅读:2435

IOS文字转语音,在语音播放过程中如何停止

分类:Native.js

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 负责人:无 分享
已邀请:
DCloud_IOS_XTY

DCloud_IOS_XTY

//停止  
sppech.stopSpeakingAtBoundary(0)  
//暂停  
sppech.pauseSpeakingAtBoundary(0);  
//继续  
sppech.continueSpeaking(0);
  • 小琪琪 (作者)

    谢谢大神,大神那你知道安卓科大讯飞的如何停止、暂停、继续吗?


    2016-03-04 09:03

1***@qq.com

1***@qq.com

声音没有出来,ios的

JBoss

JBoss

我ios的也是没有声音,但也没有报错。不知什么原因?

该问题目前已经被锁定, 无法添加新回复