如果你只是想將一個按鈕添加到您的網頁大聲朗讀網頁時,該代碼添加到您的網站:
<script src='https://code.responsivevoice.org/responsivevoice.js'></script>
<script type="text/javascript">
<!-- //
var speechpause=0;
function toggleSpeech(){
if(speechpause!=1){
responsiveVoice.pause();
speechpause=1;
}else{
responsiveVoice.resume();
speechpause=0;
}
}
//-->
</script>
<div style="float:right">
<input onclick="responsiveVoice.speak($('#some_div_with_content').text(), 'Deutsch Female', {pitch: .7});" type="button" value=" Play" />
<input onclick="toggleSpeech()" type="button" value="||" />
</div>
這使用jQuery來獲取內容的文本,但可能很容易改變。
有一個名爲'media.webspeech.synth.enabled'的'about:config'標誌,可以在Firefox中啓用'speechSynthesis'。問題依然存在,'speechSynthesis.getVoices()。length === 0'。 – dakab