| OLD | NEW |
| 1 <p id="classSummary"> | 1 <p id="classSummary"> |
| 2 Use the <code>chrome.experimental.tts</code> module to play synthesized | 2 Use the <code>chrome.tts</code> module to play synthesized |
| 3 text-to-speech (TTS) from your extension or packaged app. | 3 text-to-speech (TTS) from your extension or packaged app. |
| 4 See also the related | 4 See also the related |
| 5 <a href="experimental.ttsEngine.html">experimental.ttsEngine</a> | 5 <a href="ttsEngine.html">ttsEngine</a> |
| 6 module, which allows an extension to implement a speech engine. | 6 module, which allows an extension to implement a speech engine. |
| 7 </p> | 7 </p> |
| 8 | 8 |
| 9 <p class="note"><b>Give us feedback:</b> If you have suggestions, | 9 <p class="note"><b>Give us feedback:</b> If you have suggestions, |
| 10 especially changes that should be made before stabilizing the first | 10 especially changes that should be made before stabilizing the first |
| 11 version of this API, please send your ideas to the | 11 version of this API, please send your ideas to the |
| 12 <a href="http://groups.google.com/a/chromium.org/group/chromium-extensions">chro
mium-extensions</a> | 12 <a href="http://groups.google.com/a/chromium.org/group/chromium-extensions">chro
mium-extensions</a> |
| 13 group.</p> | 13 group.</p> |
| 14 | 14 |
| 15 <h2 id="overview">Overview</h2> | 15 <h2 id="overview">Overview</h2> |
| 16 | 16 |
| 17 <p>To enable this experimental API, visit | 17 <p>You must declare the "tts" permission |
| 18 <b>chrome://flags</b> and enable <b>Experimental Extension APIs</b>. | 18 in your extension's manifest to use this API. |
| 19 </p> |
| 19 | 20 |
| 20 <p>Chrome provides native support for speech on Windows (using SAPI | 21 <p>Chrome provides native support for speech on Windows (using SAPI |
| 21 5), Mac OS X, and Chrome OS, using speech synthesis capabilities | 22 5), Mac OS X, and Chrome OS, using speech synthesis capabilities |
| 22 provided by the operating system. On all platforms, the user can | 23 provided by the operating system. On all platforms, the user can |
| 23 install extensions that register themselves as alternative speech | 24 install extensions that register themselves as alternative speech |
| 24 engines.</p> | 25 engines.</p> |
| 25 | 26 |
| 26 <h2 id="generating_speech">Generating speech</h2> | 27 <h2 id="generating_speech">Generating speech</h2> |
| 27 | 28 |
| 28 <p>Call <code>speak()</code> from your extension or | 29 <p>Call <code>speak()</code> from your extension or |
| 29 packaged app to speak. For example:</p> | 30 packaged app to speak. For example:</p> |
| 30 | 31 |
| 31 <pre>chrome.experimental.tts.speak('Hello, world.');</pre> | 32 <pre>chrome.tts.speak('Hello, world.');</pre> |
| 32 | 33 |
| 33 <p>To stop speaking immediately, just call <code>stop()</code>: | 34 <p>To stop speaking immediately, just call <code>stop()</code>: |
| 34 | 35 |
| 35 <pre>chrome.experimental.tts.stop();</pre> | 36 <pre>chrome.tts.stop();</pre> |
| 36 | 37 |
| 37 <p>You can provide options that control various properties of the speech, | 38 <p>You can provide options that control various properties of the speech, |
| 38 such as its rate, pitch, and more. For example:</p> | 39 such as its rate, pitch, and more. For example:</p> |
| 39 | 40 |
| 40 <pre>chrome.experimental.tts.speak('Hello, world.', {'rate': 2.0});</pre> | 41 <pre>chrome.tts.speak('Hello, world.', {'rate': 2.0});</pre> |
| 41 | 42 |
| 42 <p>It's also a good idea to specify the language so that a synthesizer | 43 <p>It's also a good idea to specify the language so that a synthesizer |
| 43 supporting that language (and regional dialect, if applicable) is chosen.</p> | 44 supporting that language (and regional dialect, if applicable) is chosen.</p> |
| 44 | 45 |
| 45 <pre>chrome.experimental.tts.speak( | 46 <pre>chrome.tts.speak( |
| 46 'Hello, world.', {'lang': 'en-US', 'rate': 2.0});</pre> | 47 'Hello, world.', {'lang': 'en-US', 'rate': 2.0});</pre> |
| 47 | 48 |
| 48 <p>By default, each call to <code>speak()</code> interrupts any | 49 <p>By default, each call to <code>speak()</code> interrupts any |
| 49 ongoing speech and speaks immediately. To determine if a call would be | 50 ongoing speech and speaks immediately. To determine if a call would be |
| 50 interrupting anything, you can call <code>isSpeaking()</code>. In | 51 interrupting anything, you can call <code>isSpeaking()</code>. In |
| 51 addition, you can use the <code>enqueue</code> option to cause this | 52 addition, you can use the <code>enqueue</code> option to cause this |
| 52 utterance to be added to a queue of utterances that will be spoken | 53 utterance to be added to a queue of utterances that will be spoken |
| 53 when the current utterance has finished.</p> | 54 when the current utterance has finished.</p> |
| 54 | 55 |
| 55 <pre>chrome.experimental.tts.speak( | 56 <pre>chrome.tts.speak( |
| 56 'Speak this first.'); | 57 'Speak this first.'); |
| 57 chrome.experimental.tts.speak( | 58 chrome.tts.speak( |
| 58 'Speak this next, when the first sentence is done.', {'enqueue': true}); | 59 'Speak this next, when the first sentence is done.', {'enqueue': true}); |
| 59 </pre> | 60 </pre> |
| 60 | 61 |
| 61 <p>A complete description of all options can be found in the | 62 <p>A complete description of all options can be found in the |
| 62 <a href="#method-speak">speak() method documentation</a> below. | 63 <a href="#method-speak">speak() method documentation</a> below. |
| 63 Not all speech engines will support all options.</p> | 64 Not all speech engines will support all options.</p> |
| 64 | 65 |
| 65 <p>To catch errors and make sure you're calling <code>speak()</code> | 66 <p>To catch errors and make sure you're calling <code>speak()</code> |
| 66 correctly, pass a callback function that takes no arguments. Inside | 67 correctly, pass a callback function that takes no arguments. Inside |
| 67 the callback, check | 68 the callback, check |
| 68 <a href="extension.html#property-lastError">chrome.extension.lastError</a> | 69 <a href="extension.html#property-lastError">chrome.extension.lastError</a> |
| 69 to see if there were any errors.</p> | 70 to see if there were any errors.</p> |
| 70 | 71 |
| 71 <pre>chrome.experimental.tts.speak( | 72 <pre>chrome.tts.speak( |
| 72 utterance, | 73 utterance, |
| 73 options, | 74 options, |
| 74 function() { | 75 function() { |
| 75 if (chrome.extension.lastError) { | 76 if (chrome.extension.lastError) { |
| 76 console.log('Error: ' + chrome.extension.lastError.message); | 77 console.log('Error: ' + chrome.extension.lastError.message); |
| 77 } | 78 } |
| 78 });</pre> | 79 });</pre> |
| 79 | 80 |
| 80 <p>The callback returns right away, before the engine has started | 81 <p>The callback returns right away, before the engine has started |
| 81 generating speech. The purpose of the callback is to alert you to | 82 generating speech. The purpose of the callback is to alert you to |
| 82 syntax errors in your use of the TTS API, not to catch all possible | 83 syntax errors in your use of the TTS API, not to catch all possible |
| 83 errors that might occur in the process of synthesizing and outputting | 84 errors that might occur in the process of synthesizing and outputting |
| 84 speech. To catch these errors too, you need to use an event listener, | 85 speech. To catch these errors too, you need to use an event listener, |
| 85 described below.</p> | 86 described below.</p> |
| 86 | 87 |
| 87 <h2 id="events">Listening to events</h2> | 88 <h2 id="events">Listening to events</h2> |
| 88 | 89 |
| 89 <p>To get more real-time information about the status of synthesized speech, | 90 <p>To get more real-time information about the status of synthesized speech, |
| 90 pass an event listener in the options to <code>speak()</code>, like this:</p> | 91 pass an event listener in the options to <code>speak()</code>, like this:</p> |
| 91 | 92 |
| 92 <pre>chrome.experimental.tts.speak( | 93 <pre>chrome.tts.speak( |
| 93 utterance, | 94 utterance, |
| 94 { | 95 { |
| 95 onEvent: function(event) { | 96 onEvent: function(event) { |
| 96 console.log('Event ' + event.type ' at position ' + event.charIndex); | 97 console.log('Event ' + event.type ' at position ' + event.charIndex); |
| 97 if (event.type == 'error') { | 98 if (event.type == 'error') { |
| 98 console.log('Error: ' + event.errorMessage); | 99 console.log('Error: ' + event.errorMessage); |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 }, | 102 }, |
| 102 callback);</pre> | 103 callback);</pre> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 145 |
| 145 <p>Utterances used in this API may include markup using the | 146 <p>Utterances used in this API may include markup using the |
| 146 <a href="http://www.w3.org/TR/speech-synthesis">Speech Synthesis Markup | 147 <a href="http://www.w3.org/TR/speech-synthesis">Speech Synthesis Markup |
| 147 Language (SSML)</a>. If you use SSML, the first argument to | 148 Language (SSML)</a>. If you use SSML, the first argument to |
| 148 <code>speak()</code> should be a complete SSML document with an XML | 149 <code>speak()</code> should be a complete SSML document with an XML |
| 149 header and a top-level <code><speak></code> tag, not a document | 150 header and a top-level <code><speak></code> tag, not a document |
| 150 fragment.</p> | 151 fragment.</p> |
| 151 | 152 |
| 152 <p>For example:</p> | 153 <p>For example:</p> |
| 153 | 154 |
| 154 <pre>chrome.experimental.tts.speak( | 155 <pre>chrome.tts.speak( |
| 155 '<?xml version="1.0"?>' + | 156 '<?xml version="1.0"?>' + |
| 156 '<speak>' + | 157 '<speak>' + |
| 157 ' The <emphasis>second</emphasis> ' + | 158 ' The <emphasis>second</emphasis> ' + |
| 158 ' word of this sentence was emphasized.' + | 159 ' word of this sentence was emphasized.' + |
| 159 '</speak>');</pre> | 160 '</speak>');</pre> |
| 160 | 161 |
| 161 <p>Not all speech engines will support all SSML tags, and some may not support | 162 <p>Not all speech engines will support all SSML tags, and some may not support |
| 162 SSML at all, but all engines are required to ignore any SSML they don't | 163 SSML at all, but all engines are required to ignore any SSML they don't |
| 163 support and to still speak the underlying text.</p> | 164 support and to still speak the underlying text.</p> |
| 164 | 165 |
| 165 <h2 id="choosing_voice">Choosing a voice</h2> | 166 <h2 id="choosing_voice">Choosing a voice</h2> |
| 166 | 167 |
| 167 <p>By default, Chrome chooses the most appropriate voice for each | 168 <p>By default, Chrome chooses the most appropriate voice for each |
| 168 utterance you want to speak, based on the language and gender. On most | 169 utterance you want to speak, based on the language and gender. On most |
| 169 Windows, Mac OS X, and Chrome OS systems, speech synthesis provided by | 170 Windows, Mac OS X, and Chrome OS systems, speech synthesis provided by |
| 170 the operating system should be able to speak any text in at least one | 171 the operating system should be able to speak any text in at least one |
| 171 language. Some users may have a variety of voices available, though, | 172 language. Some users may have a variety of voices available, though, |
| 172 from their operating system and from speech engines implemented by other | 173 from their operating system and from speech engines implemented by other |
| 173 Chrome extensions. In those cases, you can implement custom code to choose | 174 Chrome extensions. In those cases, you can implement custom code to choose |
| 174 the appropriate voice, or to present the user with a list of choices.</p> | 175 the appropriate voice, or to present the user with a list of choices.</p> |
| 175 | 176 |
| 176 <p>To get a list of all voices, call <code>getVoices()</code> and pass it | 177 <p>To get a list of all voices, call <code>getVoices()</code> and pass it |
| 177 a function that receives an array of <code>TtsVoice</code> objects as its | 178 a function that receives an array of <code>TtsVoice</code> objects as its |
| 178 argument:</p> | 179 argument:</p> |
| 179 | 180 |
| 180 <pre>chrome.experimental.tts.getVoices( | 181 <pre>chrome.tts.getVoices( |
| 181 function(voices) { | 182 function(voices) { |
| 182 for (var i = 0; i < voices.length; i++) { | 183 for (var i = 0; i < voices.length; i++) { |
| 183 console.log('Voice ' + i + ':'); | 184 console.log('Voice ' + i + ':'); |
| 184 console.log(' name: ' + voices[i].voiceName); | 185 console.log(' name: ' + voices[i].voiceName); |
| 185 console.log(' lang: ' + voices[i].lang); | 186 console.log(' lang: ' + voices[i].lang); |
| 186 console.log(' gender: ' + voices[i].gender); | 187 console.log(' gender: ' + voices[i].gender); |
| 187 console.log(' extension id: ' + voices[i].extensionId); | 188 console.log(' extension id: ' + voices[i].extensionId); |
| 188 console.log(' event types: ' + voices[i].eventTypes); | 189 console.log(' event types: ' + voices[i].eventTypes); |
| 189 } | 190 } |
| 190 });</pre> | 191 });</pre> |
| OLD | NEW |