-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
80 lines (78 loc) · 2.21 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
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="pic.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🗣SPEECH TO TEXT📝</title>
<style>
body{
background-image: linear-gradient(270deg,yellow,red);
}
div{
text-align: center;
}
#textbox{
display: block;
width: 70%;
height: 23.375rem;
margin: auto;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: 0.25rem;
margin-top: 2%;
font-size: 15px;
}
button{
font-size: 30px;
margin: auto;
}
p{
font-size: 30px;
font-style: oblique;
}
</style>
</head>
<body>
<div>
<h1>speech to text converter</h1>
<textarea id="textbox" cols="40" rows="10"></textarea><br>
<button id="start">Start</button>
<button id="stop">stop</button>
<p id="instructions">press start to continue</p>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
var recognition = new SpeechRecognition();
var textbox = $("#textbox");
var instructions = $("#instructions");
var content = '';
recognition.onstart = function(){
instructions.text("voice recognition is on");
}
$('#stop').click(function(event){
recognition.stop();
instructions.text("press start to continue");
})
recognition.onerror= function(){
instructions.text("unable to recognize");
}
recognition.onresult= function(event){
var current = event.resultIndex;
var transcript = event.results[current][0].transcript;
content+=transcript;
textbox.val(content);
}
recognition.continuous = true;
$("#start").click(function(event){
if(content.length) {
content+=''
}
recognition.start()
})
</script>
</html>