Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/common/extensions/docs/server2/templates/intros/ttsEngine.html

Issue 10832042: Extensions Docs Server: Doc conversion script (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: everything but svn stuff Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <p id="classSummary"> 1 <p id="classSummary">
2 Use the <code>chrome.ttsEngine</code> module to 2 Use the <code>chrome.ttsEngine</code> module to
3 implement a text-to-speech (TTS) engine using an extension. If your 3 implement a text-to-speech (TTS) engine using an extension. If your
4 extension registers using this API, it will receive events containing 4 extension registers using this API, it will receive events containing
5 an utterance to be spoken and other parameters when any extension or packaged 5 an utterance to be spoken and other parameters when any extension or packaged
6 app uses the 6 app uses the
7 <a href="tts.html">tts</a> 7 <a href="tts.html">tts</a>
8 module to generate speech. Your extension can then use any available 8 module to generate speech. Your extension can then use any available
9 web technology to synthesize and output the speech, and send events back 9 web technology to synthesize and output the speech, and send events back
10 to the calling function to report the status. 10 to the calling function to report the status.
11 </p> 11 </p>
12
13
12 <h2 id="overview">Overview</h2> 14 <h2 id="overview">Overview</h2>
15
13 <p>An extension can register itself as a speech engine. By doing so, it 16 <p>An extension can register itself as a speech engine. By doing so, it
14 can intercept some or all calls to functions such as 17 can intercept some or all calls to functions such as
15 <a href="tts.html#method-speak"><code>speak()</code></a> and 18 <a href="tts.html#method-speak"><code>speak()</code></a> and
16 <a href="tts.html#method-stop"><code>stop()</code></a> 19 <a href="tts.html#method-stop"><code>stop()</code></a>
17 and provide an alternate implementation. 20 and provide an alternate implementation.
18 Extensions are free to use any available web technology 21 Extensions are free to use any available web technology
19 to provide speech, including streaming audio from a server, HTML5 audio, 22 to provide speech, including streaming audio from a server, HTML5 audio,
20 Native Client, or Flash. An extension could even do something different 23 Native Client, or Flash. An extension could even do something different
21 with the utterances, like display closed captions in a pop-up window or 24 with the utterances, like display closed captions in a pop-up window or
22 send them as log messages to a remote server.</p> 25 send them as log messages to a remote server.</p>
26
23 <h2 id="manifest">Manifest</h2> 27 <h2 id="manifest">Manifest</h2>
28
24 <p>To implement a TTS engine, an extension must 29 <p>To implement a TTS engine, an extension must
25 declare the "ttsEngine" permission and then declare all voices 30 declare the "ttsEngine" permission and then declare all voices
26 it provides in the extension manifest, like this:</p> 31 it provides in the extension manifest, like this:</p>
32
27 <pre>{ 33 <pre>{
28 "name": "My TTS Engine", 34 "name": "My TTS Engine",
29 "version": "1.0", 35 "version": "1.0",
30 <b>"permissions": ["ttsEngine"], 36 <b>"permissions": ["ttsEngine"],
31 "tts_engine": { 37 "tts_engine": {
32 "voices": [ 38 "voices": [
33 { 39 {
34 "voice_name": "Alice", 40 "voice_name": "Alice",
35 "lang": "en-US", 41 "lang": "en-US",
36 "gender": "female", 42 "gender": "female",
37 "event_types": ["start", "marker", "end"] 43 "event_types": ["start", "marker", "end"]
38 }, 44 },
39 { 45 {
40 "voice_name": "Pat", 46 "voice_name": "Pat",
41 "lang": "en-US", 47 "lang": "en-US",
42 "event_types": ["end"] 48 "event_types": ["end"]
43 } 49 }
44 ] 50 ]
45 },</b> 51 },</b>
46 "background_page": "background.html", 52 "background_page": "background.html",
47 }</pre> 53 }</pre>
54
48 <p>An extension can specify any number of voices.</p> 55 <p>An extension can specify any number of voices.</p>
56
49 <p>The <code>voice_name</code> parameter is required. The name should be 57 <p>The <code>voice_name</code> parameter is required. The name should be
50 descriptive enough that it identifies the name of the voice and the 58 descriptive enough that it identifies the name of the voice and the
51 engine used. In the unlikely event that two extensions register voices 59 engine used. In the unlikely event that two extensions register voices
52 with the same name, a client can specify the ID of the extension that 60 with the same name, a client can specify the ID of the extension that
53 should do the synthesis.</p> 61 should do the synthesis.</p>
62
54 <p>The <code>gender</code> parameter is optional. If your voice corresponds 63 <p>The <code>gender</code> parameter is optional. If your voice corresponds
55 to a male or female voice, you can use this parameter to help clients 64 to a male or female voice, you can use this parameter to help clients
56 choose the most appropriate voice for their application.</p> 65 choose the most appropriate voice for their application.</p>
66
57 <p>The <code>lang</code> parameter is optional, but highly recommended. 67 <p>The <code>lang</code> parameter is optional, but highly recommended.
58 Almost always, a voice can synthesize speech in just a single language. 68 Almost always, a voice can synthesize speech in just a single language.
59 When an engine supports more than one language, it can easily register a 69 When an engine supports more than one language, it can easily register a
60 separate voice for each language. Under rare circumstances where a single 70 separate voice for each language. Under rare circumstances where a single
61 voice can handle more than one language, it's easiest to just list two 71 voice can handle more than one language, it's easiest to just list two
62 separate voices and handle them using the same logic internally. However, 72 separate voices and handle them using the same logic internally. However,
63 if you want to create a voice that will handle utterances in any language, 73 if you want to create a voice that will handle utterances in any language,
64 leave out the <code>lang</code> parameter from your extension's manifest.</p> 74 leave out the <code>lang</code> parameter from your extension's manifest.</p>
75
65 <p>Finally, the <code>event_types</code> parameter is required if the engine can 76 <p>Finally, the <code>event_types</code> parameter is required if the engine can
66 send events to update the client on the progress of speech synthesis. 77 send events to update the client on the progress of speech synthesis.
67 At a minimum, supporting the <code>'end'</code> event type to indicate 78 At a minimum, supporting the <code>'end'</code> event type to indicate
68 when speech is finished is highly recommended, otherwise Chrome cannot 79 when speech is finished is highly recommended, otherwise Chrome cannot
69 schedule queued utterances.</p> 80 schedule queued utterances.</p>
81
70 <p class="note"> 82 <p class="note">
71 <strong>Note:</strong> If your TTS engine does not support 83 <strong>Note:</strong> If your TTS engine does not support
72 the <code>'end'</code> event type, Chrome cannot queue utterances 84 the <code>'end'</code> event type, Chrome cannot queue utterances
73 because it has no way of knowing when your utterance has finished. To 85 because it has no way of knowing when your utterance has finished. To
74 help mitigate this, Chrome passes an additional boolean <code>enqueue</code> 86 help mitigate this, Chrome passes an additional boolean <code>enqueue</code>
75 option to your engine's onSpeak handler, giving you the option of 87 option to your engine's onSpeak handler, giving you the option of
76 implementing your own queueing. This is discouraged because then 88 implementing your own queueing. This is discouraged because then
77 clients are unable to queue utterances that should get spoken by different 89 clients are unable to queue utterances that should get spoken by different
78 speech engines.</p> 90 speech engines.</p>
91
79 <p>The possible event types that you can send correspond to the event types 92 <p>The possible event types that you can send correspond to the event types
80 that the <code>speak()</code> method receives:</p> 93 that the <code>speak()</code> method receives:</p>
94
81 <ul> 95 <ul>
82 <li><code>'start'</code>: The engine has started speaking the utterance. 96 <li><code>'start'</code>: The engine has started speaking the utterance.
83 <li><code>'word'</code>: A word boundary was reached. Use 97 <li><code>'word'</code>: A word boundary was reached. Use
84 <code>event.charIndex</code> to determine the current speech 98 <code>event.charIndex</code> to determine the current speech
85 position. 99 position.
86 <li><code>'sentence'</code>: A sentence boundary was reached. Use 100 <li><code>'sentence'</code>: A sentence boundary was reached. Use
87 <code>event.charIndex</code> to determine the current speech 101 <code>event.charIndex</code> to determine the current speech
88 position. 102 position.
89 <li><code>'marker'</code>: An SSML marker was reached. Use 103 <li><code>'marker'</code>: An SSML marker was reached. Use
90 <code>event.charIndex</code> to determine the current speech 104 <code>event.charIndex</code> to determine the current speech
91 position. 105 position.
92 <li><code>'end'</code>: The engine has finished speaking the utterance. 106 <li><code>'end'</code>: The engine has finished speaking the utterance.
93 <li><code>'error'</code>: An engine-specific error occurred and 107 <li><code>'error'</code>: An engine-specific error occurred and
94 this utterance cannot be spoken. 108 this utterance cannot be spoken.
95 Pass more information in <code>event.errorMessage</code>. 109 Pass more information in <code>event.errorMessage</code>.
96 </ul> 110 </ul>
111
97 <p>The <code>'interrupted'</code> and <code>'cancelled'</code> events are 112 <p>The <code>'interrupted'</code> and <code>'cancelled'</code> events are
98 not sent by the speech engine; they are generated automatically by Chrome.</p> 113 not sent by the speech engine; they are generated automatically by Chrome.</p>
114
99 <p>Text-to-speech clients can get the voice information from your 115 <p>Text-to-speech clients can get the voice information from your
100 extension's manifest by calling 116 extension's manifest by calling
101 <a href="tts.html#method-getVoices">getVoices()</a>, 117 <a href="tts.html#method-getVoices">getVoices()</a>,
102 assuming you've registered speech event listeners as described below.</p> 118 assuming you've registered speech event listeners as described below.</p>
119
103 <h2 id="handling_speech_events">Handling speech events</h2> 120 <h2 id="handling_speech_events">Handling speech events</h2>
121
104 <p>To generate speech at the request of clients, your extension must 122 <p>To generate speech at the request of clients, your extension must
105 register listeners for both <code>onSpeak</code> and <code>onStop</code>, 123 register listeners for both <code>onSpeak</code> and <code>onStop</code>,
106 like this:</p> 124 like this:</p>
125
107 <pre>var speakListener = function(utterance, options, sendTtsEvent) { 126 <pre>var speakListener = function(utterance, options, sendTtsEvent) {
108 sendTtsEvent({'event_type': 'start', 'charIndex': 0}) 127 sendTtsEvent({'event_type': 'start', 'charIndex': 0})
128
109 // (start speaking) 129 // (start speaking)
130
110 sendTtsEvent({'event_type': 'end', 'charIndex': utterance.length}) 131 sendTtsEvent({'event_type': 'end', 'charIndex': utterance.length})
111 }; 132 };
133
112 var stopListener = function() { 134 var stopListener = function() {
113 // (stop all speech) 135 // (stop all speech)
114 }; 136 };
137
115 chrome.ttsEngine.onSpeak.addListener(speakListener); 138 chrome.ttsEngine.onSpeak.addListener(speakListener);
116 chrome.ttsEngine.onStop.addListener(stopListener);</pre> 139 chrome.ttsEngine.onStop.addListener(stopListener);</pre>
140
117 <p class="warning"> 141 <p class="warning">
118 <b>Important:</b> 142 <b>Important:</b>
119 If your extension does not register listeners for both 143 If your extension does not register listeners for both
120 <code>onSpeak</code> and <code>onStop</code>, it will not intercept any 144 <code>onSpeak</code> and <code>onStop</code>, it will not intercept any
121 speech calls, regardless of what is in the manifest.</p> 145 speech calls, regardless of what is in the manifest.</p>
146
122 <p>The decision of whether or not to send a given speech request to an 147 <p>The decision of whether or not to send a given speech request to an
123 extension is based solely on whether the extension supports the given voice 148 extension is based solely on whether the extension supports the given voice
124 parameters in its manifest and has registered listeners 149 parameters in its manifest and has registered listeners
125 for <code>onSpeak</code> and <code>onStop</code>. In other words, 150 for <code>onSpeak</code> and <code>onStop</code>. In other words,
126 there's no way for an extension to receive a speech request and 151 there's no way for an extension to receive a speech request and
127 dynamically decide whether to handle it.</p> 152 dynamically decide whether to handle it.</p>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698