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

Side by Side Diff: chrome/common/extensions/docs/static/experimental.ttsEngine.html

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

Powered by Google App Engine
This is Rietveld 408576698