How to convert Highlighted or Selected text to speech

Published on Author Code Father
How to convert selected text to speech? How to convert Highlighted text to speechText to speech in HTML5 ,JavaScript which runs on all browser. Selected text to speech which runs on all browser.Text to speech using Javascript.Text to speech using jquery.

HTML:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta charset="utf-8" />
 
 <script>
 var text = '';
 function gText(e) {
 text = (document.all) ? document.selection.createRange().text : document.getSelection();

 document.getElementById('sel').value = text;
 var u1 = new SpeechSynthesisUtterance(document.getElementById("sel").value);
 u1.lang = 'en-US';
 u1.pitch = 1;
 u1.rate = 1;
 //u1.voice = voices[10];
 u1.voiceURI = 'native';
 u1.volume = 1;
 speechSynthesis.speak(u1);
 }

 document.onmouseup = gText;
 if (!document.all) document.captureEvents(Event.MOUSEUP);
 </script>
 <title> </title>
</head>
<body>
 
<textarea id="sel" rows="3" cols="50" style="display:none;"></textarea>
<h2>Welcome to Text to speach Demo. Please select below text.</h2>

<ul class="list">
<li><p><b>Import required modules</b> − We use the <b>require</b></p></li>
<li><p><b>Create server</b> − A server which will listen to client's requests similar</p></li>
<li><p><b>Read request and return response</b> − The server created in an earlier step will read the HTTP request made by the client which can be a browser or a console and return the response.</p></li>
</ul><br>

 Run code snippetHide results <span style="color:red;">HWW</span>.
<p>i want to check if the particular word is exits or not in the string with ignore case.</p>

<p>My String is - "Hello world , Wassup? , good moRNING".</p>

<p>Now i want to check if the word - "hello world".</p>

<p>so i have tried the following:</p>

<p>I have also tried with <code>contains</code> but this is not working.</p>

<p>How can i find this particular word ?</p>
 </div>
</body>
</html>

 

Comments

comments