gpt4 book ai didi

javascript - 无法检测 responsiveVoice 是否正在播放()

转载 作者:行者123 更新时间:2023-11-30 12:30:30 25 4
gpt4 key购买 nike

关于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"
/>

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

最佳答案

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

//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>

关于javascript - 无法检测 responsiveVoice 是否正在播放(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27885616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com