1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../../resources/js-test.js"></script>
7 <script type=
"text/javascript">
8 description('Test basic interaction with the Speech JavaScript API');
11 // Check availability of constructors.
12 shouldBeTrue("'webkitSpeechRecognition' in self");
13 shouldBeFalse("webkitSpeechRecognition == null");
18 function oneMatchTest() {
19 debug('\noneMatchTest():');
20 var r
= new webkitSpeechRecognition();
23 r
.onstart = function() { debug('onstart'); shouldBe('count', '0'); ++count
; }
24 r
.onaudiostart = function() { debug('onaudiostart'); shouldBe('count', '1'); ++count
; }
25 r
.onsoundstart = function() { debug('onsoundstart'); shouldBe('count', '2'); ++count
; }
26 r
.onspeechstart = function() { debug('onspeechstart'); shouldBe('count', '3'); ++count
; }
28 r
.onresult = function() {
30 shouldBe('count', '4');
32 shouldBeNull('event.emma');
33 shouldBeNull('event.interpretation');
34 shouldBe('event.results.length', '1');
35 shouldBeNull('event.results.item(-1)');
36 shouldBe('event.results[0].length', '1');
37 shouldBe('event.results[0].isFinal', 'true');
38 shouldBeEqualToString('event.results[0].item(0).transcript', 'hello, world');
39 shouldBeCloseTo('event.results[0].item(0).confidence', 0.42, 1e-3);
40 shouldBeNull('event.results[0].item(-1)');
43 r
.onspeechend = function() { debug('onspeechend'); shouldBe('count', '5'); ++count
; }
44 r
.onsoundend = function() { debug('onsoundend'); shouldBe('count', '6'); ++count
; }
45 r
.onaudioend = function() { debug('onaudioend'); shouldBe('count', '7'); ++count
; }
47 r
.onend = function() {
49 shouldBe('count', '8');
54 if (window
.testRunner
) {
55 testRunner
.addMockSpeechRecognitionResult('hello, world', 0.42);
60 function noMatchTest() {
61 debug('\nnoMatchTest():');
62 var r
= new webkitSpeechRecognition();
65 r
.onstart = function() { debug('onstart'); shouldBe('count', '0'); ++count
; }
66 r
.onaudiostart = function() { debug('onaudiostart'); shouldBe('count', '1'); ++count
; }
67 r
.onsoundstart = function() { debug('onsoundstart'); shouldBe('count', '2'); ++count
; }
68 r
.onspeechstart = function() { debug('onspeechstart'); shouldBe('count', '3'); ++count
; }
70 r
.onnomatch = function() {
72 shouldBe('count', '4');
74 shouldBe('event.results', 'null');
77 r
.onspeechend = function() { debug('onspeechend'); shouldBe('count', '5'); ++count
; }
78 r
.onsoundend = function() { debug('onsoundend'); shouldBe('count', '6'); ++count
; }
79 r
.onaudioend = function() { debug('onaudioend'); shouldBe('count', '7'); ++count
; }
81 r
.onend = function() {
83 shouldBe('count', '8');
92 window
.jsTestIsAsync
= true;