Copilot JavaScript čtení textu

Vytvoř funkci, která umí přečíst text nahlas.

A table for two, please Stůl pro dva, prosím
Where is the bathroom? Kde je toaleta?
How much does this cost? Kolik to stojí?
I would like a coffee, please Chtěl bych kávu, prosím

    function speak(text) {
    const utter = new SpeechSynthesisUtterance(text);
    utter.lang = "en-GB";
    utter.rate = 0.8;
    utter.voice = voices[2];
    speechSynthesis.speak(utter);
}
    

1) Jak to funguje

function speak(text) „Vytvoř stroj jménem speak, který dostane nějaký text.“

const utter = new SpeechSynthesisUtterance(text) „Zabal ten text do balíčku, který umí mluvit.“

utter.lang = "en-US" „Mluv americkou angličtinou.“

utter.rate = 1 „Mluv normální rychlostí.“

speechSynthesis.speak(utter) „A teď to přečti nahlas.“

2) Jak se funkce používá

Když klikneš na tlačítko:

JavaScript zavolá funkci speak()

předá jí text „Hello“

a funkce ho přečte

utter.rate = 1.2; Chceš rychlejší mluvení?

utter.rate = 0.8; Chceš pomalejší mluvení?


Chceš mluvit jiným jazykem?

utter.lang = "cs-CZ"; čeština

utter.lang = "fr-FR"; francouzština

utter.lang = "de-DE"; němčina

utter.lang = "es-ES"; španělština

utter.lang = "en-GB"; britská angličtina

utter.lang = "en-US"; americká angličtina


utter.pitch = 0.8; Chceš hlubší hlas?

utter.pitch = 1.2; Chceš vyšší hlas?

const voices = speechSynthesis.getVoices(); Chceš změnit hlas?

utter.voice = voices[0]; zkus různé indexy pro různé hlasy

utter.volume = 1; Chceš hlasitější?

utter.volume = 0.5; Chceš tišší?

speechSynthesis.cancel(); Chceš zastavit mluvení?

speechSynthesis.pause(); Chceš pozastavit mluvení?

speechSynthesis.resume(); Chceš pokračovat v mluvení po pozastavení?

utter.rate = 0.8; Chceš pomalejší mluvení?

utter.rate = 1.2; Chceš rychlejší mluvení?