Javascritp: synthetic voice speaking with pauses

With this code you can add pauses at your will in a sinthesys speech.

<textarea id="lavagna" rows="5" cols="50">
</textarea>

<script>
testo = `La somministrazione
1000

è un contratto
50

in cui
30

una parte, detta somministrante,
80

si obbliga a eseguire prestazioni periodiche e continuative
100

dietro pagamento di un prezzo
60

in favore di un'altra parte
20

detta somministrato
500

articolo 1559 del codice civile
100
`

testo = testo.split("\n\n");
testo2 = "";
for (n in testo){
    x = testo[n].split("\n")
    testo2 += x[0] + "<silence msec='" + x[1] + "' />";

}
lavagna.value = testo2
</script>






<br>
<button id="buttonSpeak">Speak</button>

<script>

var utterance  = new SpeechSynthesisUtterance(),
lavagna = document.getElementById("lavagna");


// Say lavagna when button is clicked
buttonSpeak.addEventListener("click", function (event) {
    utterance.text = lavagna.value;
    speechSynthesis.speak(utterance);
});
</script>


Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.