charger_voix

This commit is contained in:
2026-01-18 15:16:53 +01:00
parent 1b6274934e
commit d3193b9013

View File

@@ -125,55 +125,54 @@ body > main {
const langue = document.documentElement.lang; const langue = document.documentElement.lang;
let voix = null; let voix = null;
if ('speechSynthesis' in window) { function charger_voix() {
speechSynthesis.onvoiceschanged = function() { let liste_voix = speechSynthesis.getVoices().filter(voice => voice.lang.startsWith(langue));
let liste_voix = speechSynthesis.getVoices().filter(voice => voice.lang.startsWith(langue)); select_voix.innerHTML = aphone;
select_voix.innerHTML = aphone;
if (!liste_voix.length) {
bouton_synthese_vocale.style.display = 'none';
return;
}
liste_voix.forEach((v, i) => {
const option = document.createElement('option');
option.value = i;
option.innerText = v.name;
select_voix.appendChild(option);
if (v.voiceURI === window.localStorage.getItem('voix')) {
select_voix.value = i;
voix = v;
option.selected = true;
bouton_synthese_vocale.innerHTML = "🕪";
}
})
bouton_synthese_vocale.style.display = 'block'; if (!liste_voix.length) {
bouton_synthese_vocale.addEventListener('click', () => { bouton_synthese_vocale.style.display = 'none';
boite_synthese_vocale.showModal(); speechSynthesis.addEventListener('voiceschanged', charger_voix);
}); return;
bouton_fermer.addEventListener('click', () => {
boite_synthese_vocale.close();
});
bouton_annuler.addEventListener('click', () => {
boite_synthese_vocale.close();
});
bouton_ok.addEventListener('click', () => {
boite_synthese_vocale.close();
if (select_voix.value) {
voix = liste_voix[select_voix.value];
window.localStorage.setItem('voix', voix.voiceURI);
bouton_synthese_vocale.innerHTML = "🕪";
} else {
voix = null;
window.localStorage.removeItem('voix');
bouton_synthese_vocale.innerHTML = "🕨";
}
});
} }
speechSynthesis.onvoiceschanged() speechSynthesis.removeEventListener('voiceschanged', charger_voix);
liste_voix.forEach((v, i) => {
const option = document.createElement('option');
option.value = i;
option.innerText = v.name;
select_voix.appendChild(option);
if (v.voiceURI === window.localStorage.getItem('voix')) {
select_voix.value = i;
voix = v;
option.selected = true;
bouton_synthese_vocale.innerHTML = "🕪";
}
})
bouton_synthese_vocale.style.display = 'block';
bouton_synthese_vocale.addEventListener('click', () => {
boite_synthese_vocale.showModal();
});
bouton_fermer.addEventListener('click', () => {
boite_synthese_vocale.close();
});
bouton_annuler.addEventListener('click', () => {
boite_synthese_vocale.close();
});
bouton_ok.addEventListener('click', () => {
boite_synthese_vocale.close();
if (select_voix.value) {
voix = liste_voix[select_voix.value];
window.localStorage.setItem('voix', voix.voiceURI);
bouton_synthese_vocale.innerHTML = "🕪";
} else {
voix = null;
window.localStorage.removeItem('voix');
bouton_synthese_vocale.innerHTML = "🕨";
}
});
} }
if ('speechSynthesis' in window) charger_voix();
question.addEventListener('keydown', e => { question.addEventListener('keydown', e => {
if (e.key === 'Enter' && !e.ctrlKey && !e.shiftKey) { if (e.key === 'Enter' && !e.ctrlKey && !e.shiftKey) {