A speech synthesizer, often known as a text-to-speech (TTS) system, is an object of technology that utilizes software to transform written text into spoken words. It is an essential component of many software applications, mobile devices, and programs that rely on verbal output to communicate effectively with users, students, and groups. Voice synthesizers transform the written text into natural-sounding speech using innovative techniques and linguistic models. There are many text-to-speech software available that can help you convert text into speech. Some of the best text-to-speech software of 2023 according to TechRadar are:
NaturalReader
Murf
Amazon Polly
Google Text-to-Speech
Speech synthesis is a multi-stage process that includes waveform production, text analysis, and language processing. The input text is analyzed first to determine the sentences, punctuation, and grammatical structures that make up the language. In order to generate speech that sounds like human speech, linguistic processing then uses rules and models to establish pronunciation, intonation, and rhythm. The language output is finally transformed into an audio signal through waveform creation, which may be heard through speakers, headphones, or extended Audio Sources.
2) Voice Assistants: Virtual voice assistants like Siri, Alexa, and Google Assistant reply to customer inquiries and deliver information through speech synthesis as a real-time response.
3) Language Translation: TTS systems provide accurate communication between speakers of many languages by facilitating real-time translation of the text into spoken speech without any human intervention.
4) Speech synthesis is utilized to generate audio versions of textual information, to get recognized within different cultures making it accessible to users. Examples include audiobooks and podcasts.
5) Navigation systems: Speech synthesis is used by GPS and navigation applications to deliver turn-by-turn directions while driving or locating the destination without any distraction resulting from reading the directions.
The speech synthesizer speaks in the enlarged window when the button is clicked.
<!DOCTYPE html>
<html>
<head>
<title>Speech Synthesizer</title>
</head>
<body>
<h1>Text to Speech</h1>
<textarea id="text-to-speech" rows="4" cols="50" placeholder="Enter text to speak"></textarea>
<button id="speak-btn">Speak</button>
<script>
// Function to speak the given text in a new window and close it after four seconds
function speakInExtendedWindow(text) {
const popupWidth = 400; // Set the width of the pop-up window
const popupHeight = 200; // Set the height of the pop-up window
// Calculate the position to center the pop-up window on the extended screen
const screenWidth = screen.width;
const screenHeight = screen.height;
const popupLeft = (screenWidth - popupWidth) / 2;
const popupTop = (screenHeight - popupHeight) / 2;
// Open a new window at the center of the extended screen
const extendedWindow = window.open('', '_blank', `width=${popupWidth}, height=${popupHeight}, left=${popupLeft}, top=${popupTop}`);
extendedWindow.document.write('<p>' + text + '</p>');
extendedWindow.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
// Close the window after four seconds
setTimeout(() => {
extendedWindow.close();
}, 4000);
}
// Check if the browser supports the Web Speech API
if ('speechSynthesis' in window) {
// Get the elements from the DOM
const textArea = document.getElementById('text-to-speech');
const speakBtn = document.getElementById('speak-btn');
// Add event listener to the Speak button
speakBtn.addEventListener('click', () => {
const textToSpeak = textArea.value.trim();
if (textToSpeak !== '') {
speakInExtendedWindow(textToSpeak);
}
});
} else {
alert('Your browser does not support speech synthesis.');
}
</script>
</body>
</html>
In the above-modified example, we have created a new function speakInExtendedWindow() that takes the text to be spoken as a parameter. When the "Speak" button is clicked, this function is called, which opens a new window using window.open(). We pass the text to speak to the new window, and the speechSynthesis interface is used to speak the text within the new window.
Please note that modern browsers often block pop-ups, so the behavior of the window.open() method may vary depending on the browser's settings. Additionally, the speechSynthesis interface may behave differently in new windows or tabs compared to the main window, depending on the user's browser and operating system settings.
Conclusion
2 Comments
only plays for few seconds.....how can it read the whole text
ReplyDeleteDear Asif it can read for 4 seconds that means 4000 milli seconds in order to read all the text you need to remove 4000 in the code .
ReplyDelete