-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
81 lines (70 loc) · 2.46 KB
/
index.html
File metadata and controls
81 lines (70 loc) · 2.46 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.tgl
{
position: absolute;
top:330px;
margin: 40px;
width: 130px;
height: 130px;
font: 13px/130px 'Barlow Semi Condensed', sans-serif;
text-transform: uppercase;
letter-spacing: 1px;
color: #fff;
text-align: center;
background: white;
border-radius: 50%;
animation: shadow-pulse 1s infinite;
}
</style>
</head>
<body>
<div class="container">
<h4> USING WEB speechRecognition API</h4>
<div id='message'>Click on mic to start</div>
<br>
<div class="inner-left">
<button id='btnGiveCommand' onclick="toogleFunction()"> <i class="fa fa-microphone" aria-hidden="true" style="font-size: 40px;"></i></button>
<br><br>
</div>
</div>
<script>
function toogleFunction() {
var element = document.getElementById("btnGiveCommand");
element.classList.toggle("tgl");
}
var message = document.querySelector('#message');
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList;
var grammar = '#JSGF V1.0;'
var recognition = new SpeechRecognition();
var speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
recognition.lang = 'en-US';
recognition.interimResults = true;
recognition.onresult = function(event) {
var last = event.results.length - 1;
var command = event.results[last][0].transcript;
message.textContent = '' + command + '.';
};
recognition.onspeechend = function() {
recognition.stop();
};
recognition.onerror = function(event) {
message.textContent = 'Error occurred in recognition: ' + event.error;
}
document.querySelector('#btnGiveCommand').addEventListener('click', function(){
recognition.start();
});
</script>
</body>
</html>