/
tts.clj
129 lines (97 loc) · 5.29 KB
/
tts.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
(ns chromex.app.tts
"Use the chrome.tts API to play synthesized text-to-speech (TTS). See also the related ttsEngine API, which allows an
extension to implement a speech engine.
* available since Chrome 36
* https://developer.chrome.com/apps/tts"
(:refer-clojure :only [defmacro defn apply declare meta let partial])
(:require [chromex.wrapgen :refer [gen-wrap-helper]]
[chromex.callgen :refer [gen-call-helper gen-tap-all-events-call]]))
(declare api-table)
(declare gen-call)
; -- functions --------------------------------------------------------------------------------------------------------------
(defmacro speak
"Speaks text using a text-to-speech engine.
|utterance| - The text to speak, either plain text or a complete, well-formed SSML document. Speech engines that do not
support SSML will strip away the tags and speak the text. The maximum length of the text is 32,768
characters.
|options| - The speech options.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/tts#method-speak."
([utterance options] (gen-call :function ::speak &form utterance options))
([utterance] `(speak ~utterance :omit)))
(defmacro stop
"Stops any current speech and flushes the queue of any pending utterances. In addition, if speech was paused, it will now be
un-paused for the next call to speak.
https://developer.chrome.com/apps/tts#method-stop."
([] (gen-call :function ::stop &form)))
(defmacro pause
"Pauses speech synthesis, potentially in the middle of an utterance. A call to resume or stop will un-pause speech.
https://developer.chrome.com/apps/tts#method-pause."
([] (gen-call :function ::pause &form)))
(defmacro resume
"If speech was paused, resumes speaking where it left off.
https://developer.chrome.com/apps/tts#method-resume."
([] (gen-call :function ::resume &form)))
(defmacro is-speaking
"Checks whether the engine is currently speaking. On Mac OS X, the result is true whenever the system speech engine is
speaking, even if the speech wasn't initiated by Chrome.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [speaking] where:
|speaking| - True if speaking, false otherwise.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/tts#method-isSpeaking."
([] (gen-call :function ::is-speaking &form)))
(defmacro get-voices
"Gets an array of all available voices.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [voices] where:
|voices| - Array of 'tts.TtsVoice' objects representing the available voices for speech synthesis.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/tts#method-getVoices."
([] (gen-call :function ::get-voices &form)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.app.tts namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.tts",
:since "36",
:functions
[{:id ::speak,
:name "speak",
:callback? true,
:params
[{:name "utterance", :type "string"}
{:name "options", :optional? true, :type "tts.TtsOptions"}
{:name "callback", :optional? true, :type :callback}]}
{:id ::stop, :name "stop"}
{:id ::pause, :name "pause"}
{:id ::resume, :name "resume"}
{:id ::is-speaking,
:name "isSpeaking",
:callback? true,
:params
[{:name "callback", :optional? true, :type :callback, :callback {:params [{:name "speaking", :type "boolean"}]}}]}
{:id ::get-voices,
:name "getVoices",
:callback? true,
:params
[{:name "callback",
:optional? true,
:type :callback,
:callback {:params [{:name "voices", :type "[array-of-tts.TtsVoices]"}]}}]}]})
; -- helpers ----------------------------------------------------------------------------------------------------------------
; code generation for native API wrapper
(defmacro gen-wrap [kind item-id config & args]
(apply gen-wrap-helper api-table kind item-id config args))
; code generation for API call-site
(def gen-call (partial gen-call-helper api-table))