【发布时间】:2015-11-24 19:20:33
【问题描述】:
这可以正常工作,它会在点击时说出文本区域,但我怎样才能将其更改为说出 onload?
<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"> HHHH</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>
文本区域现在只显示四个字母。
我想这是关键部分,但无法将其放入任何正确执行的内容中:
responsiveVoice.speak($('#text').val(),$('US English Female').val());
我试过了:
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)
})
$(document).ready(function() { //short code: $(function() { ... });
responsiveVoice.speak($('#text').val(), $('US English Female').val());
});
<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">It reads this</textarea>
<select id="voiceselection"></select>
<script>
</script>
<input onclick="responsiveVoice.speak($('#text').val(),$('US English Female').val());" type="button" value="Play" />
但我收到“未找到语音:未定义”错误。
【问题讨论】:
-
$('US English Female')不是有效的 HTML 元素。responsiveVoice.speak($('#text').val(), 'US English Female') -
就像在 cmets 和答案中提到的那样,问题不在于语音选择(api 和库 应该 回退到默认值)问题是语音有尚未加载。
标签: javascript jquery function onload responsivevoice