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

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

Issue 7282048: Update TTS extension API docs to reflect latest changes. Note that this (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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <p id="classSummary">
2 Use the <code>chrome.experimental.tts_engine</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 the intended utterance 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 manually specify the extension id to
68 receive speech calls.</p>
69
70 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.
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.
82
83 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 recommend, otherwise it's impossible
87 for Chrome to schedule queued utterances.</p>
88
89 <p class="note">If your TTS engine does not support the <code>'end'</code>
90 event type, Chrome will pass the <code>enqueue</code> option to
91 onSpeak, so that your engine can implement its own queuing. However, this is
92 discouraged because it means that users cannot queue utterances that get
93 sent to different speech engines.</p>
94
95 <p>The possible event types you can send correspond to the event types that
96 the <code>speak()</code> method receives:</p>
97
98 <ul>
99 <li><code>'start'</code>: the engine has started speaking the utterance.
100 <li><code>'word'</code>: a word boundary was reached. Use
101 <code>event.charIndex</code> to determine the current speech
102 position.
103 <li><code>'sentence'</code>: a sentence boundary was reached. Use
104 <code>event.charIndex</code> to determine the current speech
105 position.
106 <li><code>'marker'</code>: an SSML marker was reached. Use
107 <code>event.charIndex</code> to determine the current speech
108 position.
109 <li><code>'end'</code>: the engine has finished speaking the utterance.
110 <li><code>'error'</code>: An engine-specific error occurred and
111 this utterance cannot be spoken.
112 Pass more information in <code>event.errorMessage</code>.
113 </ul>
114
115 <p>The <code>'interrupted'</code> and <code>'cancelled'</code> events are
116 not sent by the speech engine; they are generated automatically by Chrome.</p>
117
118 <p>The information about your extensions's voices from your manifest
119 will be returned to any client that calls <code>getVoices</code>, assuming
120 you've also registered speech event listeners as described below.</p>
121
122 <h2 id="handling_speech_events">Handling Speech Events</h2>
123
124 <p>To generate speech at the request of clients, your extension must
125 register listeners for both <code>onSpeak</code> and <code>onStop</code>,
126 like this:</p>
127
128 <pre>var speakListener = function(utterance, options, sendTtsEvent) {
129 sendTtsEvent({'event_type': 'start', 'charIndex': 0})
130
131 // (start speaking)
132
133 sendTtsEvent({'event_type': 'end', 'charIndex': utterance.length})
134 };
135
136 var stopListener = function() {
137 // (stop all speech)
138 };
139
140 chrome.experimental.tts.onSpeak.addListener(speakListener);
141 chrome.experimental.tts.onStop.addListener(stopListener);</pre>
142
143 <p class="warning">If an extension does not register listeners for both
144 <code>onSpeak</code> and <code>onStop</code>, it will not intercept any
145 speech calls, regardless of what is in the manifest.</p>
146
147 <p>The decision of whether or not to send a given speech request to an
148 extension is based solely on whether the extension supports the given voice
149 parameters in its manifest and has registered listeners
150 for <code>onSpeak</code> and <code>onStop</code>. In other words,
151 there's no way for an extension to receive a speech request and
152 dynamically decide whether to handle it or not.</p>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698