blob: 36e58b4bf68879bfafd6d95bbd05a9089e9ed9ac [file] [log] [blame] [view]
Katie Ded1a9972018-04-17 16:22:181# Text to Speech in Chrome and Chrome OS
2
3Chrome and Chrome OS allow developers to produce synthesized speech. This
4document is an overview of the relevant code and code structure around
5synthesized speech.
6
7## Code structure
8
9A brief outline of the flow from speech request to the resulting speech on any
10platform.
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 D8f959ec2018-12-07 22:23:0025 [tts_controller Utterance](https://cs.chromium.org/chromium/src/content/public/browser/tts_controller.h?dr=CSs&l=120).
Katie Ded1a9972018-04-17 16:22:1826
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 D8f959ec2018-12-07 22:23:0040- 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 Violet1644cf72020-06-24 04:51:5544(in chrome/) provides chrome OS specific functionality.
Katie Ded1a9972018-04-17 16:22:1845
46### Output
47
48- May differ by system, including Mac, Wind, Android, Arc++, and Chrome OS
49
Katie D8f959ec2018-12-07 22:23:0050 - 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 Ded1a9972018-04-17 16:22:1853- 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 Tseng7f8ddfb2021-11-01 19:32:5959 - [PATTS](../os/patts.md) is the built-in Chrome OS text-to-speech engine.
Katie D8f959ec2018-12-07 22:23:0060
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 Violet1644cf72020-06-24 04:51:5578 (currently Windows only).