-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
75 lines (62 loc) · 1.85 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Echo</title>
</head>
<link rel="icon" type="image/png" sizes="16x16" href="https://e7.pngegg.com/pngimages/435/40/png-clipart-computer-icons-ninja-favicon-iconfinder-avatar-warrior-drawing-share-icon-user.png">
<body>
<img src="https://i.gifer.com/B6mG.gif">
<p class = 'center'>Tap mic & speak to echo </p>
<div id ='echo'>
<img alt="Echo" id = 'voice' src="https://images.techhive.com/images/article/2014/03/google-voice-search-100248800-large.jpg">
<img alt="Echo" id = 'voice-animate' src="https://s3.amazonaws.com/images.seroundtable.com/google-voice-search-1413374736.gif" >
</div>
</body>
<style>
#echo{
height: auto;
width: 400px;
position: absolute;
display: block;
left: 35%;
top: 35%;
}
#voice-animate{
position: absolute;
top: 90px;
right: 5px;
z-index: 2;
visibility:hidden
}
.center {
position: absolute;
bottom: 5%;
left: 50%;
}
</style>
<script>
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent
var recognition = new SpeechRecognition();
var speechRecognitionList = new SpeechGrammarList();
document.addEventListener('click', function(e){
if(e.target.id == 'voice'){
document.getElementById('voice-animate').style.visibility = 'visible';
recognition.start();
}
});
recognition.onresult = function(event) {
console.log('Success: ' + event.results[0][0].transcript);
speak(event.results[0][0].transcript)
}
recognition.onspeechend = function() {
recognition.stop();
document.getElementById('voice-animate').style.visibility = 'hidden';
}
function speak(output){
let utterance = new SpeechSynthesisUtterance(output);
speechSynthesis.speak(utterance);
}
</script>
</html>