Bez odkładania raz na zawsze
Projekt e-booka kierowanego do uczniów oraz studentów.
Elementy projektu:


Projekt e-booka kierowanego do uczniów oraz studentów.
<style>
#voice-reader-btn {
position: fixed;
left: 0;
top: 50%;
transform: translateY(-50%);
background: #000;
color: #fff;
padding: 12px 14px;
font-size: 16px;
z-index: 9999;
cursor: pointer;
border-radius: 0 8px 8px 0;
font-family: sans-serif;
}
</style>
<button id="voice-reader-btn">🔊 Czytaj</button>
<script>
document.getElementById("voice-reader-btn").addEventListener("click", function () {
const utterance = new SpeechSynthesisUtterance();
const lang = "pl-PL";
const content = document.querySelector("main")?.innerText || document.body.innerText;
utterance.text = content;
utterance.lang = lang;
const voices = window.speechSynthesis.getVoices();
const polishVoice = voices.find(voice => voice.lang === lang);
if (polishVoice) {
utterance.voice = polishVoice;
}
window.speechSynthesis.cancel(); // na wypadek, gdyby już coś czytało
window.speechSynthesis.speak(utterance);
});
</script>