Katie D | ed1a997 | 2018-04-17 16:22:18 | [diff] [blame^] | 1 | # Text to Speech in Chrome and Chrome OS |
| 2 | |
| 3 | Chrome and Chrome OS allow developers to produce synthesized speech. This |
| 4 | document is an overview of the relevant code and code structure around |
| 5 | synthesized speech. |
| 6 | |
| 7 | ## Code structure |
| 8 | |
| 9 | A brief outline of the flow from speech request to the resulting speech on any |
| 10 | platform. |
| 11 | |
| 12 | ### Input |
| 13 | |
| 14 | - chrome.tts extension API |
| 15 | |
| 16 | - The [chrome.tts extension API](https://developer.chrome.com/apps/tts) |
| 17 | allows extensions to request speech across Windows, Mac or Chrome OS, using |
| 18 | native speech synthesis. |
| 19 | |
| 20 | - Input to the extension is first processed in the |
| 21 | [TtsExtensionApi](https://cs.chromium.org/chromium/src/chrome/browser/speech/extension_api/tts_extension_api.h). |
| 22 | |
| 23 | - The extension is passed an [Options object](https://developer.chrome.com/apps/tts#method-speak) |
| 24 | in chrome.tts.speak, which is translated into a |
| 25 | [tts_controller Utterance](https://cs.chromium.org/chromium/src/chrome/browser/speech/tts_controller.h?dr=CSs&l=130). |
| 26 | |
| 27 | - Web Speech API |
| 28 | |
| 29 | - Chrome implements |
| 30 | [Window.SpeechSynthesis](https://developer.mozilla.org/en-US/docs/Web/API/Window/speechSynthesis) |
| 31 | from the [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API). |
| 32 | This allows web apps to do text-to-speech via the device's speech |
| 33 | synthesizer. |
| 34 | |
| 35 | - A [WebSpeechSynthesisUtterance](https://cs.chromium.org/chromium/src/third_party/blink/public/platform/web_speech_synthesis_utterance.h) |
| 36 | is created by window.SpeechSynthesis |
| 37 | |
| 38 | ### Processing |
| 39 | |
| 40 | - The [TtsController](https://cs.chromium.org/chromium/src/chrome/browser/speech/tts_controller.h) processes utterances and sends them to the correct output engine |
| 41 | |
| 42 | ### Output |
| 43 | |
| 44 | - May differ by system, including Mac, Wind, Android, Arc++, and Chrome OS |
| 45 | |
| 46 | - In Chrome OS: |
| 47 | |
| 48 | - [TtsEngineExtensionAPI](https://cs.chromium.org/chromium/src/chrome/browser/speech/extension_api/tts_engine_extension_api.h) |
| 49 | forwards speech events to PATTS, or the network speech engine, or, |
| 50 | coming soon, third-party speech engines. |
| 51 | |
| 52 | - [PATTS](patts.md) is the built-in Chrome OS text-to-speech engine. |