http://responsivevoice.org上关于isPlaying()的信息不多。
以下是我尝试过的不起作用的东西。我没有得到console.log()。
setInterval(function(){ // continuously check if the audio is being played
if(responsiveVoice.isPlaying()){
console.log('playing..');
},
100
);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://responsivevoice.org/responsivevoice/responsivevoice.js"></script>
<textarea id="text" cols="45" rows="3">Hello, world!</textarea>
<input
onclick="responsiveVoice.speak($('#text').val(),'US English Female');"
type="button"
value="Play"
/>
如何检测音频是否正在播放?还有,有什么方法可以在音频播放完毕后得到回调吗?
发布于 2015-06-12 15:58:30
谢谢你使用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
发布于 2015-03-06 02:48:41
他们实际上使用的是语音API的window.speechSynthesis对象。所以您可以检查它的playing布尔值。
//Their code
var voicelist = responsiveVoice.getVoices();
var vselect = $("#voiceselection");
$.each(voicelist, function() {
vselect.append($("<option />").val(this.name).text(this.name));
});
// Yours
$('#isPlaying').on('click', function() {
$('#r').text(window.speechSynthesis.speaking)
})<script src="http://responsivevoice.org/responsivevoice/responsivevoice.js"></script>
<script src="http://code.jquery.com/jquery-git2.js"></script>
<textarea id="text" cols="45" rows="3">Hello world this is some text to say</textarea>
<select id="voiceselection"></select>
<input onclick="responsiveVoice.speak($('#text').val(),$('#voiceselection').val());" type="button" value="Play" />
<br>
<button id="isPlaying">Playing:</button>
<p id="r">?</p>
发布于 2015-01-11 09:53:25
Audio标记具有paused属性。如果它没有暂停,那么它就在播放。所以:
function isPlaying(audelem) {
return !audelem.paused;
}
$('audio').on('play ended',function() {
setInterval(function(){
if(isPlaying(this)){
console.log('playing...');
}
}, 100);
});https://stackoverflow.com/questions/27885616
复制相似问题