Ionic2 如何在Ionic 2中停止TextToSpeech
我无法停止Ionic TextToSpeech的播放。 下面是我正在调用的函数:Ionic2 如何在Ionic 2中停止TextToSpeech,ionic2,text-to-speech,Ionic2,Text To Speech,我无法停止Ionic TextToSpeech的播放。 下面是我正在调用的函数: ... speaking : boolean = false; ... sayText(txt:string, loc: string){ if (this.speaking){ this.tts.stop(); // <<< does not seem to work? this.speaking = false; return; } this.s
...
speaking : boolean = false;
...
sayText(txt:string, loc: string){
if (this.speaking){
this.tts.stop(); // <<< does not seem to work?
this.speaking = false;
return;
}
this.speaking = true;
this.tts.speak( {text: txt, locale: loc} )
.then((val) => { this.speaking = false; },
(reject) => {console.warn(reject); this.speaking = false; })
.catch((err) => {console.error(err); this.speaking = false; });
}
我错过什么了吗?
谢谢。呼叫tts。用空字符串说话以中断
sayText(txt:string, loc: string){
if(this.speaking){
this.tts.speak({text: ''}); // <<< speak an empty string to interrupt.
this.speaking = false;
return;
}
this.speaking = true;
this.tts.speak( {text: txt, locale: loc} )
.then((val) => { this.speaking = false; },
(reject) => {console.warn(reject); this.speaking = false; })
.catch((err) => {console.error(err); this.speaking = false; });
}
sayText(txt:string,loc:string){
如果(我是这个){
this.tts.speak({text:'});//{console.warn(拒绝);this.speak=false;})
.catch((err)=>{console.error(err);this.speaking=false;});
}
使用空字符串调用tts.speak以中断
sayText(txt:string, loc: string){
if(this.speaking){
this.tts.speak({text: ''}); // <<< speak an empty string to interrupt.
this.speaking = false;
return;
}
this.speaking = true;
this.tts.speak( {text: txt, locale: loc} )
.then((val) => { this.speaking = false; },
(reject) => {console.warn(reject); this.speaking = false; })
.catch((err) => {console.error(err); this.speaking = false; });
}
sayText(txt:string,loc:string){
如果(我是这个){
this.tts.speak({text:'});//{console.warn(拒绝);this.speak=false;})
.catch((err)=>{console.error(err);this.speaking=false;});
}
Simple.And works.我最喜欢的答案。:)谢谢。出于好奇,.stop()方法做什么?在最新的tts插件中没有stop()方法。查看这里的提示->Simple.And works.我最喜欢的答案。:)谢谢。出于好奇,.stop()方法做什么?No stop()方法。请查看此处的提示->