Javascript ResponsiveVoice呼叫一次,多个语音只能回拨一次
我想用相应的声音强调特定的段落/列表 responsivevoice.js中是否有回调。我得到了一个作为回调函数的ONED。但它不起作用 每当我放置console而不是highlight时,它只生成一个而不是三个 我认为ONED是在第一段之后打电话的。但它应该适用于所有段落/ul 请帮帮我 我的代码:-Javascript ResponsiveVoice呼叫一次,多个语音只能回拨一次,javascript,callback,text-to-speech,responsivevoice,Javascript,Callback,Text To Speech,Responsivevoice,我想用相应的声音强调特定的段落/列表 responsivevoice.js中是否有回调。我得到了一个作为回调函数的ONED。但它不起作用 每当我放置console而不是highlight时,它只生成一个而不是三个 我认为ONED是在第一段之后打电话的。但它应该适用于所有段落/ul 请帮帮我 我的代码:- <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="http://code.responsivevoice.org/develop/1.5.2/responsivevoice.js"></script>
<script>
var currentDataValue =0;
$( document ).ready(function(){
$("#1").click(function(){
$("p,ul").each(function( index, element){
responsiveVoice.speak($(this).text(),$('UK English Female').val(),{
pitch: .7,
onend: function() {
$(this).css( "backgroundColor", "yellow" );
}
});
});
});
});
$( document ).ready(function(){
$("#2").click(function(){
responsiveVoice.pause();
});
});
$( document ).ready(function(){
$("#3").click(function(){
responsiveVoice.resume();
});
});
$(window).load(function(){
$("#4").click(function(){
responsiveVoice.cancel();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<ul>
<li>this unoder list </li>
</ul>
<p id="test">This is another paragraph.</p>
<button id="1">start</button>
<button id="2">pause</button>
<button id="3">resume</button>
<button id="4">stop</button>
</body>
</html>
var currentDataValue=0;
$(文档).ready(函数(){
$(“#1”)。单击(函数(){
$(“p,ul”)。每个(函数(索引,元素){
responsiveVoice.speak($(this).text(),$('UK English Femal').val(){
音高:.7,
onend:function(){
$(this.css(“backgroundColor”,“yellow”);
}
});
});
});
});
$(文档).ready(函数(){
$(“#2”)。单击(函数(){
(停顿);
});
});
$(文档).ready(函数(){
$(“#3”)。单击(函数(){
resume();
});
});
$(窗口)。加载(函数(){
$(“#4”)。单击(函数(){
responsiveVoice.cancel();
});
});
这是一个标题
这是一段
- 这是未订购清单
这是另一段
开始
暂停
简历
停止
这个ResponsiveVoice是一个带有bug的商业库,它为回调设置了一个变量,因此它只调用最后配置的回调,而不是所有回调。当然,您可以修改库,也可以这样逐个调用项:
$("#1").click(function(){
var elements = $("p, ul");
speak = function(i, elements) {
responsiveVoice.speak($(elements[i]).text(),$('UK English Female').val(),{
pitch: .7,
onend: function() {
$(elements[i]).css("backgroundColor", "yellow");
if (i < elements.length) {
speak(i + 1, elements);
}
}
});
};
speak(0, elements);
});
var currentDataValue =0;
$( document ).ready(function(){
$("#1").click(function(){
var voice = speechSynthesis.getVoices().filter(function(voice){return voice.name == 'Allison'; })[0];
$("p,ul").each(function(index, element) {
u = new SpeechSynthesisUtterance($(this).text());
u.voice = voice;
u.onend = (function() {
console.log("Here");
$(this).css( "background-color", "yellow" );
}).bind($(this));
speechSynthesis.speak(u);
});
});
});
谢谢你的回复。语音正常工作,但问题是只有一个回拨,而不是每个段落/ul都正常工作。你也可以通过$(this.css(“backgroundColor”,“yellow”);用一些日志(打印)。它只打印了一次。但是在每个段落/ul的语音合成之后应该是3次。因为,他们(响应语音)处理了很多案例。比如:-大的句子(超过200个单词),语音质量,浏览器的兼容性等等。所以我在使用它们。如果我像u一样(对演示有效),那么我必须处理很多案例。