From 1859ff16854fc82d8ccc57f3a2db097e056438ba Mon Sep 17 00:00:00 2001 From: adrien Date: Tue, 20 Jan 2026 13:28:07 +0100 Subject: [PATCH] voix_selectionnee --- index.html | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/index.html b/index.html index 831df18..3bc31d2 100644 --- a/index.html +++ b/index.html @@ -63,17 +63,12 @@ body > main { content: "😸 "; } -/*#question { - padding-right: 2rem; -}*/ - #bouton_reconnaissance_vocale { position: absolute; right: 0; width: 2rem; height: 100%; padding-left: 0; - padding-right: 0.5rem; border: none; z-index: 10; } @@ -122,7 +117,7 @@ body > main {
@@ -146,6 +141,8 @@ const bouton_annuler = document.getElementById('bouton_annuler'); const bouton_ok = document.getElementById('bouton_ok'); const footer = document.querySelector('footer'); const langue = document.documentElement.lang; + +let voix_selectionnee = null; let utterance = null; question.onkeydown = function(e) { @@ -187,7 +184,7 @@ formulaire.addEventListener('submit', async (e) => { const reponse = await requete.text(); paragraphe.setAttribute('aria-busy', 'false'); - if (utterance?.voice) { + if (voix_selectionnee) { utterance.text = reponse; speechSynthesis.speak(utterance); } @@ -231,28 +228,20 @@ function charger_voix() { } speechSynthesis.removeEventListener('voiceschanged', charger_voix); - - utterance = new SpeechSynthesisUtterance(); - utterance.lang = langue; - utterance.rate = 1; liste_voix.forEach((voix, i) => { const option = document.createElement('option'); option.value = i; - option.textContent = `${voix.name} (${voix.lang})`; + option.textContent = voix.name; select_voix.appendChild(option); - if (voix.voiceURI === window.localStorage.getItem('voix')) { + if (voix.voiceURI === voix_selectionnee) { + option.selected = true; select_voix.value = i; utterance.voice = voix; - option.selected = true; bouton_synthese_vocale.innerHTML = ``; } }) - bouton_synthese_vocale.disabled = false; - bouton_synthese_vocale.onclick = function() { - boite_synthese_vocale.showModal(); - }; bouton_fermer.onclick = bouton_annuler.onclick = function() { boite_synthese_vocale.close(); }; @@ -261,18 +250,30 @@ function charger_voix() { if (select_voix.value) { let voix = liste_voix[select_voix.value]; utterance.voice = voix; - window.localStorage.setItem('voix', voix.voiceURI); + voix_selectionnee = voix.voiceURI; + window.localStorage.setItem('voiceURI', voix.voiceURI); bouton_synthese_vocale.innerHTML = ``; } else { - utterance.voice = null; - window.localStorage.removeItem('voix'); + voix_selectionnee = null; + window.localStorage.removeItem('voiceURI'); bouton_synthese_vocale.innerHTML = ``; } }; + bouton_synthese_vocale.onclick = function() { + boite_synthese_vocale.showModal(); + }; + bouton_synthese_vocale.disabled = false; } + if ('speechSynthesis' in window) { - bouton_synthese_vocale.style.display = 'block'; + voix_selectionnee = window.localStorage.getItem('voiceURI'); + + utterance = new SpeechSynthesisUtterance(); + utterance.lang = langue; + utterance.rate = 1; + charger_voix(); + bouton_synthese_vocale.style.display = 'block'; } // Reconnaissance vocale