-
Notifications
You must be signed in to change notification settings - Fork 2
/
speech.js
67 lines (57 loc) · 2.33 KB
/
speech.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
click_to_record.addEventListener('click',
function()
{
var social =
{
"open youtube" : "https://www.youtube.com/",
"open twitter" : "https://twitter.com/home",
"open instagram" : "https://www.instagram.com/",
"open gmail" : "https://mail.google.com/",
"open mail" : "https://mail.google.com/",
"open quora" : "https://www.quora.com/",
"compose mail" : "https://mail.google.com/mail/u/0/#inbox?compose=new",
"twitter post" : "https://twitter.com/compose/tweet",
"google images":"https://www.google.co.in/imghp?hl=en&tab=ri&authuser=0&ogbl",
"open spotify" : "https://open.spotify.com/",
}
var speech = true;
window.SpeechRecognition = window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.interimResults = true;
recognition.addEventListener('result', e =>
{
const transcript = Array.from(e.results)
.map(result => result[0])
.map(result => result.transcript)
.join('')
document.getElementById("convert_text").innerHTML = transcript;
for(var i in social)
{
if(transcript.toLowerCase().includes(i))
{
window.open(social[i]);
}
}
if(transcript.toLowerCase().includes("ishihara test"))
{
document.getElementById("test1").click();
}
else if(transcript.toLowerCase().includes("cambridge test"))
{
document.getElementById("test2").click();
}
else if(transcript.toLowerCase().includes("solution"))
{
document.getElementById("gotoSol").click();
}
});
if (speech == true)
{
recognition.start();
}
});
//speech_help.addEventListener('click',
//function()
//{
//chrome.tts.speak("I will now explain you the keywords used for the voice assistant.........Open is used for opening a website......Compase mail to compose a mail......Post tweet to post a tweet......Cambridge test or Ishihara test to take the respective test",{'rate': 1});
//});