forked from matiyau/STTTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTTTS.html
71 lines (68 loc) · 1.86 KB
/
STTTS.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Please Wait. . .</title>
</head>
<body onload="startDictation(event)">
<div id="results">
<span id="confm"></span>
<span id="dicey"></span>
</div>
<script type="text/javascript">
var confmSTT = '';
if ('webkitSpeechRecognition' in window) {
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.onerror = function(event) {
console.log(event.error);
};
recognition.onresult = function(event) {
var diceySTT = '';
for (var i = event.resultIndex; i < event.results.length; ++i) {
word = event.results[i][0].transcript;
if (event.results[i].isFinal) {
confmSTT += word;
}
else {
diceySTT += word;
}
}
confmSTT = capitalize(confmSTT);
confm.innerHTML = linebreak(confmSTT);
dicey.innerHTML = linebreak(diceySTT);
var confmStop = confmSTT.toUpperCase().indexOf(stopCom.toUpperCase());
var diceyStop = diceySTT.toUpperCase().indexOf(stopCom.toUpperCase());
if (confmStop>0 || diceyStop>0){
recognition.abort();
stopMatch = new RegExp(stopCom, "i");
dicey.replace(stopMatch, "");
confm.innerHTML = linebreak(confmSTT);
document.title = "Done";
}
};
recognition.onspeechend = function(event) {
recognition.abort();
document.title = "Done";
};
}
var two_line = /\n\n/g;
var one_line = /\n/g;
var stopCom = "FINISH";
function linebreak(s) {
return s.replace(two_line, '<p></p>').replace(one_line, '<br>');
}
function capitalize(s) {
return s.replace(s.substr(0,1), function(m) {return m.toUpperCase();});
}
function startDictation(event) {
confmSTT = '';
recognition.lang = 'en-IN';
document.title = "Recording";
recognition.start();
confm.innerHTML = '';
dicey.innerHTML = '';
}
</script>
</body>
</html>