As per the documentation my page has to contain
<script src="https://code.responsivevoice.org/responsivevoice.js?key=YOUR_UNIQUE_KEY"></script>
I would like to avoid hardcoding my API key into index.html and to keep it in a separate file. I tried adding the responsivevoice script using js like:
const rvScript = document.createElement('script');
const api_key = "XXXXXXXX"
const src = 'https://code.responsivevoice.org/responsivevoice.js?key=' + api_key;
rvScript.setAttribute('src',src);
rvScript.onload = () => {
console.log(responsiveVoice.getVoices());
responsiveVoice.speak('Hello world')
}
document.body.appendChild(rvScript);
I get a list of voices in the console but "Hello world" is not played back.
Any ideas how to resolve this?