如果responsiveVoice isPlaying()则无法检测

有关isPlaying() http://responsivevoice.org上有很多信息。

这是我尝试过的不起作用。 我没有得到console.log()

 setInterval(function(){ // continuously check if the audio is being played if(responsiveVoice.isPlaying()){ console.log('playing..'); }, 100 ); 
     

如何检测音频是否正在播放? 此外,有没有办法在音频播放完成后获得回调?

感谢您使用ResponsiveVoice!

自v1.3.4起,我们已将函数isPlaying()添加到ResponsiveVoice并更新了API文档。

你现在可以使用:

 responsiveVoice.isPlaying() 

适用于原生SpeechSynthesis和后备音频TTS。

你可以在这里得到它:

http://code.responsivevoice.org/develop/1.3/responsivevoice.js (指向1.3.x周期中的最新版本)

还要获得具体版本:

http://code.responsivevoice.org/develop/1.3.4/responsivevoice.js

它们实际上是使用语音API的window.speechSynthesis对象。 所以你可以检查它的playing布尔值。

 //Their code var voicelist = responsiveVoice.getVoices(); var vselect = $("#voiceselection"); $.each(voicelist, function() { vselect.append($("").val(this.name).text(this.name)); }); // Yours $('#isPlaying').on('click', function() { $('#r').text(window.speechSynthesis.speaking) }) 
      

?

Audio标签具有paused属性。 如果它没有暂停,那么它正在播放。 所以:

 function isPlaying(audelem) { return !audelem.paused; } $('audio').on('play ended',function() { setInterval(function(){ if(isPlaying(this)){ console.log('playing...'); } }, 100); }); 

isPlaying方法似乎并不存在。 我能够使用responsiveVoice.OnFinishedPlaying钩子创建一个解决方案。 这是一个你可以设置的function,只要讲话完成就会被调用。 这是一个小小的kludgy,但可以包装如下,以在文本完成时触发回调。 当然,如果您在上一个文本完成之前尝试再次开始讲话,则会发生故障。

 function speak(text, voice, callback) { if (callback) { responsiveVoice.OnFinishedPlaying = function () { responsiveVoice.OnFinishedPlaying = null; callback(); }; } responsiveVoice.speak(text, voice); } 

“音频播放完毕后有没有办法获得回叫?”

是!! 在查看了responsiveVoice代码之后,这个解决方案对我有用:

 responsiveVoice.speak(text, voice, {"onend": function() { msgonend(text); }}); 

什么时候:

 function msgonend(text) { console.log("'" + text + "' ended."); ... } };