-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
82 lines (60 loc) · 2.29 KB
/
script.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var speechRecognition = window.webkitSpeechRecognition
var recognition = new speechRecognition()
var textbox = $("#textbox")
var textbox1 = $("#textbox1")
var instructions = $("#status")
var content = ''
recognition.lang = 'en-US';
recognition.continous = true
recognition.onstart = function(){
instructions.text("voice recognition is on")
document.getElementById("play").src = "stop-fill.svg";
}
recognition.onspeechend = function(){
instructions.text("No Activity")
document.getElementById("start-btn").className ="btn btn-success btn-block mr-2 visually-hidden";
recognition.stop();
}
recognition.onerror = function(){
instructions.text("try again")
document.getElementById("play").src = "play-fill.svg";
}
recognition.onresult = function(event){
var current = event.resultIndex;
var transcript = event.results[current][0].transcript;
content += transcript;
textbox.val(content);
if (transcript.toLowerCase() === '1.')
{
textbox1.val("You Find JOKER")
document.getElementById("satu").src = "joker.png";
document.getElementById("dua").src = "as.png";
document.getElementById("tiga").src = "as.png";
document.getElementById("start-btn").className ="btn btn-success btn-block mr-2 visually-hidden";
document.getElementById("textbox1").className ="form-control text-light bg-success text-center";
}
else if(transcript.toLowerCase()=== '2.')
{
textbox1.val("He is not here..")
document.getElementById("dua").src = "as.png";
document.getElementById("textbox1").className ="form-control text-light bg-danger text-center";
document.getElementById("start-btn").className ="btn btn-success btn-block mr-2 visually-hidden";
}
else if(transcript.toLowerCase() === '3.')
{
textbox1.val("He is not here..")
document.getElementById("tiga").src = "as.png";
document.getElementById("textbox1").className ="form-control text-light bg-danger text-center";
document.getElementById("start-btn").className ="btn btn-success btn-block mr-2 visually-hidden";
}
}
$("#start-btn").click(function(event){
if(content.length){
content += ''
}
recognition.start()
})
function eraseText(){
document.getElementById("textbox").value = "";
document.getElementById("textbox1").value = "";
}