TTS in Twine

:SugarCube: SugarCube 2

SugarCube 2.37.3 - I want to implement TTS. I can't even get a drop down list of the voices. What am I doing wrong?

This works: https://codepen.io/Aaron-Krashen/pen/raVQdvy

This doesn't work but it is the exact same code copied and pasted. I also tried running it from the Start passage and a normal passage tagged init:

:: StoryCaption {"position":"550,200","size":"100,100"}
Testing

<center><select id="voiceSelect"></select></center>
    
<<script>>

const voiceSelect = document.getElementById('voiceSelect');
let voices = [];

// Populate the voices dropdown
function populateVoiceList() {
    voices = speechSynthesis.getVoices();
    voiceSelect.innerHTML = '';

    voices.forEach(voice => {
        console.log(voice.name);
        const option = document.createElement('option');
        option.textContent = voice.name + ' (' + voice.lang + ')';
        voiceSelect.appendChild(option);
    });
}

// Populate the voice list when voices are loaded
if (speechSynthesis.onvoiceschanged !== undefined) {
    speechSynthesis.onvoiceschanged = populateVoiceList;
} else {
    populateVoiceList();  // For older browsers
}

<</script>>

I tried adding some console logs and it looks like this never gets called: populateVoiceList()

Posted Jun 23, 2025, 4:22 AM UTC

210
Loading comments…