xxxxxxxxxx
43
let synth;
let sentence = "Hello, welcome to Digital You, where your creative mind is transported and immersed into the technological world. No more thinking, no more creating, no more working, no more endless hours. Everything is assisted. You may now begin.";
let words = sentence.split(' ');
let currentWordIndex = 0;
let started = false; // Flag to indicate if speech synthesis has started
function setup() {
createCanvas(windowWidth, windowHeight);
textAlign(CENTER, CENTER);
textAlign(CENTER, CENTER);
textSize(36);
synth = window.speechSynthesis;
}
function draw() {
background(0);
fill(0, 255, 0);
if (started) { // Only display words if speech synthesis has started
for (let i = 0; i < currentWordIndex; i++) {
text(words[i], width / 2, height / 2 - 50 * (currentWordIndex - i));
}
}
}
function speakNextWord() {
let utterance = new SpeechSynthesisUtterance(words[currentWordIndex]);
utterance.lang = 'en-US';
utterance.onend = function() {
currentWordIndex++;
if (currentWordIndex < words.length) {
speakNextWord();
}
};
synth.speak(utterance);
}
function mousePressed() {
if (!started) { // Start speech synthesis only if it hasn't already started
speakNextWord();
started = true;
}
}