-
Notifications
You must be signed in to change notification settings - Fork 1
/
rec.js
49 lines (40 loc) · 1.43 KB
/
rec.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
var i=0;
function speechToTextConversion()
{
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent
var recognition = new SpeechRecognition();
recognition.continuous = true;
recognition.lang = 'en-IN';
recognition.interimResults = true;
recognition.maxAlternatives = 1;
var diagnostic = document.getElementById('text');
var i=0;
var j=0;
document.getElementById("playButton").onclick = function() {
if(i==0)
{
document.getElementById("playButton").src="record-button-thumb.png";
recognition.start();
i=1;
}
else
{
document.getElementById("playButton").src="mic.png";
recognition.stop();
i=0;
}
}
recognition.onresult = function(event) {
var last = event.results.length - 1;
var convertedText = event.results[last][0].transcript;
diagnostic.value = convertedText;
console.log('Confidence: ' + event.results[0][0].confidence);
}
recognition.onnomatch = function(event) {
diagnostic.value = 'I didnt recognise that.';
}
recognition.onerror = function(event) {
diagnostic.value = 'Error occurred in recognition: ' + event.error;
}
};