OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Dummy implementation of TTS for testing. | 6 * @fileoverview Dummy implementation of TTS for testing. |
7 * | 7 * |
8 */ | 8 */ |
9 | 9 |
10 goog.provide('cvox.TestTts'); | 10 goog.provide('cvox.TestTts'); |
(...skipping 19 matching lines...) Expand all Loading... | |
30 * @type {string} | 30 * @type {string} |
31 * @private | 31 * @private |
32 */ | 32 */ |
33 cvox.TestTts.prototype.sentinelText_ = '@@@STOP@@@'; | 33 cvox.TestTts.prototype.sentinelText_ = '@@@STOP@@@'; |
34 | 34 |
35 | 35 |
36 /** | 36 /** |
37 * @override | 37 * @override |
38 */ | 38 */ |
39 cvox.TestTts.prototype.speak = function(text, queueMode, opt_properties) { | 39 cvox.TestTts.prototype.speak = function(text, queueMode, opt_properties) { |
40 this.utterances_.push({text: text, queueMode: queueMode}); | 40 this.utterances_.push({text: text, |
41 queueMode: queueMode, | |
42 properties: opt_properties}); | |
41 if (opt_properties && opt_properties['endCallback'] != undefined) { | 43 if (opt_properties && opt_properties['endCallback'] != undefined) { |
42 var len = this.utterances_.length; | 44 var len = this.utterances_.length; |
43 // 'After' is a sentinel value in the tests that tells TTS to stop and | 45 // 'After' is a sentinel value in the tests that tells TTS to stop and |
44 // ends callbacks being called. | 46 // ends callbacks being called. |
45 if (this.utterances_[len - 1].text != | 47 if (this.utterances_[len - 1].text != |
46 this.sentinelText_) { | 48 this.sentinelText_) { |
47 opt_properties['endCallback'](); | 49 opt_properties['endCallback'](); |
48 } | 50 } |
49 } | 51 } |
50 }; | 52 }; |
(...skipping 24 matching lines...) Expand all Loading... | |
75 * @return {string} A single string containing all utterances spoken | 77 * @return {string} A single string containing all utterances spoken |
76 * since initialization or the last call to clearUtterances, | 78 * since initialization or the last call to clearUtterances, |
77 * concatenated together with all whitespace collapsed to single | 79 * concatenated together with all whitespace collapsed to single |
78 * spaces. | 80 * spaces. |
79 */ | 81 */ |
80 cvox.TestTts.prototype.getUtterancesAsString = function() { | 82 cvox.TestTts.prototype.getUtterancesAsString = function() { |
81 return cvox.DomUtil.collapseWhitespace(this.getUtteranceList().join(' ')); | 83 return cvox.DomUtil.collapseWhitespace(this.getUtteranceList().join(' ')); |
82 }; | 84 }; |
83 | 85 |
84 /** | 86 /** |
87 * Processes the utterances spoken the same way the speech queue does, | |
88 * as if they were all generated one after another, with no delay between | |
89 * them, and returns a list of strings that would be output. | |
90 * | |
91 * For example, if two strings were spoken with a queue mode of FLUSH, | |
92 * only the second string will be returned. | |
93 * @return {Array.<string>} A list of strings representing the speech output. | |
94 */ | |
95 cvox.TestTts.prototype.getSpeechQueueOutput = function() { | |
96 var queue = []; | |
97 for (var i = 0; i < this.utterances_.length; i++) { | |
98 var utterance = this.utterances_[i]; | |
99 switch (utterance.queueMode) { | |
100 case cvox.AbstractTts.QUEUE_MODE_FLUSH: | |
101 queue = []; | |
102 break; | |
103 case cvox.AbstractTts.QUEUE_MODE_QUEUE: | |
104 break; | |
105 case cvox.AbstractTts.QUEUE_MODE_CATEGORY_FLUSH: | |
106 var oldQueue = queue; | |
David Tseng
2014/09/26 22:42:20
You could just
(pseudocode)
if utterance has categ
dmazzoni
2014/09/26 22:51:49
Done.
| |
107 queue = []; | |
108 if (utterance.properties && utterance.properties.category) { | |
109 for (var i = 0; i < oldQueue.length; i++) { | |
110 if (!oldQueue[i].properties || | |
111 oldQueue[i].properties.category != | |
112 utterance.properties.category) { | |
113 queue.push(oldQueue[i]); | |
114 } | |
115 } | |
116 } | |
117 break; | |
118 } | |
119 queue.push(utterance); | |
David Tseng
2014/09/26 22:42:20
Did you mean to push here?
dmazzoni
2014/09/26 22:51:49
Yes
| |
120 } | |
121 | |
122 var result = []; | |
David Tseng
2014/09/26 22:42:20
queue.map() seems like a good pattern here.
dmazzoni
2014/09/26 22:51:49
Done.
| |
123 for (var i = 0; i < queue.length; i++) { | |
124 result.push(queue[i].text); | |
125 } | |
126 return result; | |
127 }; | |
128 | |
129 /** | |
85 * Return a list of strings of what was spoken by tts.speak(). | 130 * Return a list of strings of what was spoken by tts.speak(). |
86 * @return {Array.<string>} A list of all utterances spoken since | 131 * @return {Array.<string>} A list of all utterances spoken since |
87 * initialization or the last call to clearUtterances. | 132 * initialization or the last call to clearUtterances. |
88 */ | 133 */ |
89 cvox.TestTts.prototype.getUtteranceList = function() { | 134 cvox.TestTts.prototype.getUtteranceList = function() { |
90 var result = []; | 135 var result = []; |
91 for (var i = 0; i < this.utterances_.length; i++) { | 136 for (var i = 0; i < this.utterances_.length; i++) { |
92 result.push(this.utterances_[i].text); | 137 result.push(this.utterances_[i].text); |
93 } | 138 } |
94 return result; | 139 return result; |
95 }; | 140 }; |
96 | 141 |
97 /** | 142 /** |
98 * Return a list of strings of what was spoken by tts.speak(). | 143 * Return a list of strings of what was spoken by tts.speak(). |
99 * @return {Array.<{text: string, queueMode: number}>} | 144 * @return {Array.<{text: string, queueMode: number}>} |
100 * A list of info about all utterances spoken since | 145 * A list of info about all utterances spoken since |
101 * initialization or the last call to clearUtterances. | 146 * initialization or the last call to clearUtterances. |
102 */ | 147 */ |
103 cvox.TestTts.prototype.getUtteranceInfoList = function() { | 148 cvox.TestTts.prototype.getUtteranceInfoList = function() { |
104 return this.utterances_; | 149 return this.utterances_; |
105 }; | 150 }; |
106 | 151 |
107 /** @override */ | 152 /** @override */ |
108 cvox.HostFactory.ttsConstructor = cvox.TestTts; | 153 cvox.HostFactory.ttsConstructor = cvox.TestTts; |
OLD | NEW |