3 <title>speechreco test
</title>
6 document
.getElementById('log').innerHTML
= '';
11 var t
= d
.getHours() + ':' +
12 d
.getMinutes() + ':' +
13 d
.getSeconds() + '.' +
15 var table
= document
.getElementById('log');
16 var row
= table
.insertRow(-1);
17 var cell1
= row
.insertCell(-1);
18 var time
= document
.createElement("pre");
20 cell1
.appendChild(time
);
21 var cell2
= row
.insertCell(-1);
22 var message
= document
.createElement("pre");
23 message
.innerHTML
= msg
;
24 cell2
.appendChild(message
);
27 function res2str(results
) {
28 if (!results
|| !results
.length
)
31 for (var i
= 0; i
< results
.length
; ++i
) {
32 s
+= " " + i
+ ":{";
38 for (var i
= 0; i
< r
.length
; ++i
) {
39 s
+= r
.item(i
).transcript
+ ' (' + r
.item(i
).confidence
+ ')';
40 if (i
!= r
.length
- 1)
41 s
+= ',<br> ';
51 window
.reco
= new webkitSpeechRecognition();
53 document
.write("The Web Speech API is not supported by this browser.");
57 reco
.maxAlternatives
= 25;
59 // Set default handlers.
60 for (var prop
in reco
) {
61 if (!prop
.match('^on'))
63 reco
[prop
] = function() {
64 log('on' + event
.type
);
68 // Set specific handlers.
69 reco
.onerror = function(e
) {
70 log('onerror ' + e
.error
);
72 reco
.onresult = function(e
) {
74 log('onresult ' + res2str(e
.results
));
76 log('onresult - exception');
80 if (reco
.onresults
!= undefined) {
81 log('onresults exists');
84 log('created reco object');
89 reco
.continuous
= document
.getElementById('continuous').checked
;
90 reco
.interimResults
= document
.getElementById('interim').checked
;
91 log('reco.continuous = ' + reco
.continuous
);
92 log('reco.interimResults = ' + reco
.interimResults
);
96 log('exception: ' + e
);
110 function startOther() {
112 var other
= new webkitSpeechRecognition();
113 other
.continuous
= true;
115 // Set default handlers.
116 for (var prop
in other
) {
117 if (!prop
.match('^on'))
119 other
[prop
] = function() {
120 log('other on' + event
.type
);
128 <body onload=
"setup()">
129 <input type=
"button" onclick=
"cls()" value=
"cls">
130 <input type=
"button" onclick=
"start()" value=
"start()">
131 <input type=
"button" onclick=
"stop()" value=
"stop()">
132 <input type=
"button" onclick=
"abort()" value=
"abort()">
133 <input type=
"button" onclick=
"startOther()" value=
"startOther()">
134 <input type=
"checkbox" checked
id=
"continuous">continuous
135 <input type=
"checkbox" checked
id=
"interim">interimResults
136 <!-- <pre id="log"></pre> -->
137 <table id=
"log" width=
"350px" border=
"0"></table>