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
content / test / data / speech / web_speech_recognition.html [blame]
<!doctype html>
<meta charset="utf-8">
<title> Web Speech Recognition </title>
<script>
var successes = 0;
var hash = window.location.hash;
var recognizer = new webkitSpeechRecognition();
(function () {
switch (hash) {
// Just probe if creating a SpeechRecognition object worked.
case "#precheck":
notify(recognizer == null ? 'fail' : 'success');
return;
case "#oneshot":
recognizer.continuous = false;
break;
case "#continuous":
recognizer.continuous = true;
break;
default:
return;
}
recognizer.onresult = function(e) {
var value = e.results[e.resultIndex][0].transcript;
if (value == 'Pictures of the moon') {
successes++;
notify('goodresult' + successes);
} else {
notify('badresult');
}
}
recognizer.onerror = function(e) {
console.log('error', e);
notify('error' + e.error);
}
recognizer.onnomatch = function() { console.log('nomatch'); }
recognizer.onaudiostart = function() { console.log('audiostart'); }
recognizer.onsoundstart = function() { console.log('soundstart'); }
recognizer.onsoundend = function() { console.log('soundend'); }
recognizer.onaudioend = function() { console.log('audioend'); }
recognizer.lang = "en-US";
recognizer.start();
})();
function notify(status) {
document.location = '#' + status;
document.location.reload(true);
}
</script>