a way in javascript for speech to text in windows electron/cordova

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



a way in javascript for speech to text in windows electron/cordova



i have searched and found a lot of ways to make speech to text app for i phone /android. but i need for windows, that is all.



my code



var r = document.getElementById('result');



function execute(command)
const exec = require('child_process').exec


exec(command, (err, stdout, stderr) =>
process.stdout.write(stdout)
)





function startConverting ()
console.log("started")
document.getElementById("result").style = "position: absolute;top: 240px;left: 250px;width: 85%;height: 200px;padding: 10px;margin-bottom: 30px;font-size: 14px;line-height: 25px;background: #38afffaf;animation: result 2s infinite;animation: width 1s;"

if('webkitSpeechRecognition' in window)
var speechRecognizer = new webkitSpeechRecognition();
speechRecognizer.continuous = true;
speechRecognizer.interimResults = true;
speechRecognizer.lang = 'en-IN';
speechRecognizer.start();


var finalTranscripts = '';

speechRecognizer.onresult = function(event)
var interimTranscripts = '';
for(var i = event.resultIndex; i < event.results.length; i++)
var transcript = event.results[i][0].transcript;
transcript.replace("n", "<br>");
if(event.results[i].isFinal)
finalTranscripts += transcript;
else
interimTranscripts += transcript;



r.innerHTML = finalTranscripts + '<span style="color:#999">' + interimTranscripts + '</span>';
console.log(finalTranscripts);
//all if elses

if (finalTranscripts.indexOf("who are you") >= 0)
var msg = new SpeechSynthesisUtterance("Hello, I am khay see ly us and i am created by ahmed shahrair");
window.speechSynthesis.speak(msg);


else if(finalTranscripts.indexOf("date") >= 0)
var date1 = new Date().getDate();
var date2 = new Date().getMonth();

if (date2 == 0)
date2 = "January"
else if( date2 == 1)
date2 = "February"
else if( date2 == 2)
date2 = "March"
else if( date2 == 3)
date2 = "April"
else if( date2 == 4)
date2 = "May"
else if( date2 == 5)
date2 = "June"
else if( date2 == 6)
date2 = "July"
else if( date2 == 7)
date2 = "August"
else if( date2 == 8)
date2 = "September"
else if( date2 == 9)
date2 = "October"
else if( date2 == 10)
date2 = "November"
else if( date2 == 11)
date2 = "December"


var date3 = new Date().getFullYear()
date1 = "The date is "+ date2 + date1+ " " + date3
var msg = new SpeechSynthesisUtterance(date1)
console.log(msg)
console.log(date1)
window.speechSynthesis.speak(msg);


else if(finalTranscripts.indexOf("time") >= 0)

var hours1 = "the time is " + new Date().getHours();

if(hours1 > 12)
hours1 = hours1 - 12 , "p m"
console.log(hours1);
var msg = new SpeechSynthesisUtterance(hours1)
console.log(msg)
console.log(hours1)
window.speechSynthesis.speak(msg);

else
hours1 = hours1 + "a m"
var msg = new SpeechSynthesisUtterance(hours1)
console.log(msg)
console.log(hours1)
window.speechSynthesis.speak(msg);



else if(finalTranscripts.indexOf("day") >= 0)

var day1 = new Date().getDay();
console.log(day1)
if(day1 == 0)
day1 = "Today is Sunday"
var msg = new SpeechSynthesisUtterance(day1)
console.log(msg)
console.log(day1)
window.speechSynthesis.speak(msg);

else if( day1 == 1)
day1 = "Today is Monday"
var msg = new SpeechSynthesisUtterance(day1)
console.log(msg)
console.log(day1)
window.speechSynthesis.speak(msg);
else if( day1 == 2)
day1 = "Today is Tuesday"
var msg = new SpeechSynthesisUtterance(day1)
console.log(msg)
console.log(day1)
window.speechSynthesis.speak(msg);
else if( day1 == 3)
day1 = "Today is Wedneday"
var msg = new SpeechSynthesisUtterance(day1)
console.log(msg)
console.log(day1)
window.speechSynthesis.speak(msg);
else if( day1 == 4)
day1 = "Today is Thursday"
var msg = new SpeechSynthesisUtterance(day1)
console.log(msg)
console.log(day1)
window.speechSynthesis.speak(msg);
else if( day1 == 5)
day1 = "Today is friday"
var msg = new SpeechSynthesisUtterance(day1)
console.log(msg)
console.log(day1)
window.speechSynthesis.speak(msg);
else if( day1 == 6)
day1 = "Today is saturday"
var msg = new SpeechSynthesisUtterance(day1)
console.log(msg)
console.log(day1)
window.speechSynthesis.speak(msg);



else if(finalTranscripts.indexOf("month") >= 0)
var date2 = new Date().getMonth();

if (date2 == 1)
date2 = "January"
else if( date2 == 2)
date2 = "February"
else if( date2 == 3)
date2 = "March"
else if( date2 == 4)
date2 = "April"
else if( date2 == 5)
date2 = "May"
else if( date2 == 6)
date2 = "June"
else if( date2 == 7)
date2 = "July"
else if( date2 == 8)
date2 = "August"
else if( date2 == 9)
date2 = "September"
else if( date2 == 10)
date2 = "October"
else if( date2 == 11)
date2 = "November"
else if( date2 == 12)
date2 = "Decenber"



date2 = "The month is "+ date2
var msg = new SpeechSynthesisUtterance(date2)
console.log(msg)
console.log(date2)
window.speechSynthesis.speak(msg);


else if(finalTranscripts.indexOf("open") >= 0)
var msg = finalTranscripts
var res = finalTranscripts.replace("open", "start");
execute(res)

else if(finalTranscripts.indexOf("start") >= 0)
var msg = finalTranscripts
execute(msg)



finalTranscripts = ""; msg = "";

;
speechRecognizer.onerror = function (event)
;
else
r.innerHTML = 'The application is not supported in your Computer. please upgrade you windows!';











By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard