with the text
innerDiv.innerText = text;
speakText(text); // Call the Web Speech API function
});
});
});
// Function to speak text using the Web Speech API
function speakText(text) {
if ('speechSynthesis' in window) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.volume = 1; // Volume (0 to 1)
utterance.rate = 1; // Speed (0.1 to 10)
utterance.pitch = 1; // Pitch (0 to 2)
window.speechSynthesis.speak(utterance);
} else {
console.error("Your browser does not support the Web Speech API.");
}
}
$w.onReady(() => {
// Access the HTML component by its ID
const htmlComponent = $w('#speechTrigger');
const innerDiv = htmlComponent.$children[0]; // First child element
// Add an event listener to the inner
innerDiv.addEventListener('change', (event) => {
const text = event.target.innerText;
speakText(text); // Call the Web Speech API function
});
// Call the backend function to get the announcement text
getAnnouncementText().then((text) => {
// Update the inner
with the text
innerDiv.innerText = text;
innerDiv.dispatchEvent(new Event('change')); // Trigger the event
});
});
// Function to speak text using the Web Speech API
function speakText(text) {
if ('speechSynthesis' in window) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.volume = 1; // Volume (0 to 1)
utterance.rate = 1; // Speed (0.1 to 10)
utterance.pitch = 1; // Pitch (0 to 2)
window.speechSynthesis.speak(utterance);
} else {
console.error("Your browser does not support the Web Speech API.");
}
}