If you look at the responsive voice code they have a weird ~200 millisecond timeout in their code:
a.enableFallbackMode()) : setTimeout(function() {
var b = setInterval(function() {
var c = window.speechSynthesis.getVoices();
0 != c.length || null != a.systemvoices &&
0 != a.systemvoices.length ? (console.log("RV: Voice support ready"),
a.systemVoicesReady(c),
clearInterval(b)) : (console.log("Voice support NOT ready"),
a.voicesupport_attempts++,
a.voicesupport_attempts > a.VOICESUPPORT_ATTEMPTLIMIT && (clearInterval(b),
null != window.speechSynthesis ? a.iOS ? (a.iOS9 ? a.systemVoicesReady(a.cache_ios9_voices) : a.systemVoicesReady(a.cache_ios_voices),
console.log("RV: Voice support ready (cached)")) : (console.log("RV: speechSynthesis present but no system voices found"),
a.enableFallbackMode()) :
a.enableFallbackMode()))
}, 100)
}, 100);
a.Dispatch("OnLoad")
If you try to use a voice before the timeout is up you will hit this console log:
1570RV: ERROR: No voice found for: US English Female
Which in my experience is bad and should probably be throwing an error.
If you want to keep using this script the only solution is to wait at least 201 ms in order to wait for all of the voices to load (but you only have to do this once)
let readItOnce = false;
function read(){
const readIt = () => {
readItOnce = true;
responsiveVoice.speak('Lily, you can not just freeze me out like this.','US English Female');
responsiveVoice.speak('Love you.','US English Female');
}
if (!readItOnce) { setTimeout(readIt, 201)}
else { readIt(); }
}
Also do what is suggested here: https://stackoverflow.com/a/36654326/561731 in the onload of the function.
<html>
<head>
<script src="https://code.responsivevoice.org/responsivevoice.js"></script>
<script type="text/javascript">
let readItOnce = false;
function read(){
const readIt = () => {
readItOnce = true;
responsiveVoice.speak('Lily, you can not just freeze me out like this.','US English Female');
responsiveVoice.speak('Love you.','US English Female');
}
if (!readItOnce) { setTimeout(readIt, 201)}
else { readIt(); }
}
</script>
</head>
<body onload="read();">
</body>
</html>
javascript:
part. You only use those on href properties of anchors, etc. Even then, I wouldn't use it. I'd hook into a click event before I'd use a javascript protocol. – ManoDestra