1# 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
25    [tts_controller Utterance](https://cs.chromium.org/chromium/src/content/public/browser/tts_controller.h?dr=CSs&l=120).
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 [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)
44(in chrome/) provides chrome OS specific functionality.
45
46### Output
47
48- May differ by system, including Mac, Wind, Android, Arc++, and Chrome OS
49
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
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
59    - [PATTS](patts.md) is the built-in Chrome OS text-to-speech engine.
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
78    (currently Windows only).
79