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 |
Katie D | 8f959ec | 2018-12-07 22:23:00 | [diff] [blame] | 25 | [tts_controller Utterance](https://cs.chromium.org/chromium/src/content/public/browser/tts_controller.h?dr=CSs&l=120). |
Katie D | ed1a997 | 2018-04-17 16:22:18 | [diff] [blame] | 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 | |
Katie D | 8f959ec | 2018-12-07 22:23:00 | [diff] [blame] | 40 | - The [TtsControllerImpl](https://cs.chromium.org/chromium/src/content/browser/speech/tts_controller_impl.h) |
| 41 | (in content/) processes utterances and sends them to the correct output engine. |
| 42 | |
| 43 | - The [TtsControllerDelegateImpl](https://cs.chromium.org/chromium/src/chrome/browser/speech/tts_controller_delegate_impl.h) |
Scott Violet | 1644cf7 | 2020-06-24 04:51:55 | [diff] [blame] | 44 | (in chrome/) provides chrome OS specific functionality. |
Katie D | ed1a997 | 2018-04-17 16:22:18 | [diff] [blame] | 45 | |
| 46 | ### Output |
| 47 | |
| 48 | - May differ by system, including Mac, Wind, Android, Arc++, and Chrome OS |
| 49 | |
Katie D | 8f959ec | 2018-12-07 22:23:00 | [diff] [blame] | 50 | - Platform APIs are in [content/browser/speech](https://cs.chromium.org/chromium/src/content/browser/speech/), expect for |
| 51 | Chrome OS's, which is in [chrome/browser/speech](https://cs.chromium.org/chromium/src/chrome/browser/speech/). |
| 52 | |
Katie D | ed1a997 | 2018-04-17 16:22:18 | [diff] [blame] | 53 | - In Chrome OS: |
| 54 | |
| 55 | - [TtsEngineExtensionAPI](https://cs.chromium.org/chromium/src/chrome/browser/speech/extension_api/tts_engine_extension_api.h) |
| 56 | forwards speech events to PATTS, or the network speech engine, or, |
| 57 | coming soon, third-party speech engines. |
| 58 | |
David Tseng | 7f8ddfb | 2021-11-01 19:32:59 | [diff] [blame] | 59 | - [PATTS](../os/patts.md) is the built-in Chrome OS text-to-speech engine. |
Katie D | 8f959ec | 2018-12-07 22:23:00 | [diff] [blame] | 60 | |
| 61 | ### Testing |
| 62 | |
| 63 | - Unit tests |
| 64 | |
| 65 | - TtsControllerUnittest in content/browser/speech |
| 66 | |
| 67 | - TtsControllerDelegateImplUnittest in chrome/browser/speech |
| 68 | |
| 69 | - ArcTtsServiceUnittest for ARC++ voices |
| 70 | |
| 71 | - Browser tests |
| 72 | |
| 73 | - TtsApiTest tests Chrome TTS extension APIs |
| 74 | |
| 75 | - Fuzzer |
| 76 | |
| 77 | - In content_unittests, content/browser/speech/tts_platform_fuzzer.cc |
Scott Violet | 1644cf7 | 2020-06-24 04:51:55 | [diff] [blame] | 78 | (currently Windows only). |