-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswiftmac-voices.el
303 lines (251 loc) · 9.06 KB
/
swiftmac-voices.el
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
;;; swiftmac-voices.el --- Define Swiftmac tags -*- lexical-binding: t; -*-
;; $Id: swiftmac-voices.el 6342 2024-04-20 19:12:40Z tv.raman.tv $
;; $Author: Robert Melton $
;; Description: Module to set up Swiftmac voices and personalities
;; Keywords: Voice, Personality, Swiftmac
;;; LCD Archive entry:
;; LCD Archive Entry:
;; emacspeak| T. V. Raman |[email protected]
;; A speech interface to Emacs |
;;
;; $Revision: 4532 $ |
;; Location https://github.com/tvraman/emacspeak
;;
;;; Copyright:
;; Copyright (C) 1995 -- 2024, T. V. Raman
;; All Rights Reserved.
;;
;; This file is not part of GNU Emacs, but the same permissions apply.
;;
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Commentary:
;; This module defines the various voices used in voice-lock mode by SwiftMac TTS.
;;; Code:
;; Required modules:
(eval-when-compile (require 'cl-lib))
(require 'emacspeak-preamble) ;For `ems--fastload'.
(cl-declaim (optimize (safety 0) (speed 3)))
;;; swiftmac:
;;;###autoload
(defun swiftmac ()
"SwiftMac TTS."
(interactive)
(swiftmac-configure-tts)
(ems--fastload "voice-defs")
(dtk-select-server "swiftmac")
(dtk-initialize))
;;; Customizations:
(defcustom swiftmac-default-speech-rate 0.65
"Default speech rate for swiftmac."
:group 'tts
:type 'float
:set #'(lambda(sym val)
(set-default sym val)
(when (string-match "swiftmac\\'"dtk-program)
(setq-default dtk-speech-rate val))))
;;; voice table
; when this is set it makes dtk-set-language do nothing
; (defvar swiftmac-default-voice-string "[{voice en-US:Alex}]"
(defvar swiftmac-default-voice-string "[{voice :Alex}] [[pitch 1]]"
"Default swiftmac tag for default . Empty uses system default")
(defvar swiftmac-voice-table (make-hash-table)
"Association between symbols and strings to set SwiftMac voices.
The string can set any voice parameter.")
(defun swiftmac-define-voice (name command-string)
"Define a SwiftMac voice named NAME.
This voice will be set by sending the string
COMMAND-STRING to the TTS engine."
(cl-declare (special swiftmac-voice-table))
(puthash name command-string swiftmac-voice-table))
(defun swiftmac-get-voice-command-internal (name)
"Retrieve command string for voice NAME."
(cl-declare (special swiftmac-voice-table))
(cond
((listp name)
(mapconcat #'swiftmac-get-voice-command name " "))
(t (or (gethash name swiftmac-voice-table)
swiftmac-default-voice-string))))
(defun swiftmac-get-voice-command (name)
"Retrieve command string for voice NAME."
(swiftmac-get-voice-command-internal name))
(defun swiftmac-voice-defined-p (name)
"Check if there is a voice named NAME defined."
(cl-declare (special swiftmac-voice-table))
(gethash name swiftmac-voice-table))
;;; voice definitions
;; the predefined voices:
(swiftmac-define-voice 'paul swiftmac-default-voice-string)
;; Modified voices:
;;; Mapping css parameters to tts codes
;;; voice family codes
(defun swiftmac-get-family-code (name)
"Get control code for voice family NAME."
(swiftmac-get-voice-command-internal name))
;;; hash table for mapping families to their dimensions
(defvar swiftmac-css-code-tables (make-hash-table)
"Hash table holding vectors of swiftmac codes.
Keys are symbols of the form <FamilyName-Dimension>.
Values are vectors holding the control codes for the 10 settings.")
(defun swiftmac-css-set-code-table (family dimension table)
"Set up voice FAMILY.
Argument DIMENSION is the dimension being set,
and TABLE gives the values along that dimension."
(cl-declare (special swiftmac-css-code-tables))
(let ((key (intern (format "%s-%s" family dimension))))
(puthash key table swiftmac-css-code-tables)))
(defun swiftmac-css-get-code-table (family dimension)
"Retrieve table of values for specified FAMILY and DIMENSION."
(cl-declare (special swiftmac-css-code-tables))
(let ((key (intern (format "%s-%s" family dimension))))
(gethash key swiftmac-css-code-tables)))
;;; average pitch
;; Average pitch for standard male voice is 65 --this is mapped to
;; a setting of 5.
;; Average pitch varies inversely with speaker head size --a child
;; has a small head and a higher pitched voice.
;; We change parameter head-size in conjunction with average pitch to
;; produce a more natural change on the TTS engine.
;;; paul average pitch
(let ((table (make-vector 10 "")))
(mapc
#'(lambda (setting)
(aset table
(cl-first setting)
(format " [[average-pitch %s]] "
(cl-second setting))))
'(
(0 1)
(1 10)
(2 20)
(3 35)
(4 40)
(5 45)
(6 50)
(7 55)
(8 58)
(9 62)))
(swiftmac-css-set-code-table 'paul 'average-pitch table))
(defun swiftmac-get-average-pitch-code (value family)
"Get AVERAGE-PITCH for specified VALUE and FAMILY."
(or family (setq family 'paul))
(if value
(aref (swiftmac-css-get-code-table family 'average-pitch)
value)
""))
;;; pitch range
;; Standard pitch range is 30 and is mapped to
;; a setting of 5.
;; A value of 0 produces a flat monotone voice --maximum value of 100
;; produces a highly animated voice.
;;; paul pitch range
(let ((table (make-vector 10 "")))
(mapc
#'(lambda (setting)
(aset table
(cl-first setting)
(format " [[pitch-range %s]] "
(cl-second setting))))
'(
(0 0)
(1 14.1)
(2 28.2)
(3 42.3)
(4 56.4)
(5 70.5)
(6 84.6)
(7 98.7)
(8 112.8)
(9 127)))
(swiftmac-css-set-code-table 'paul 'pitch-range table))
(defun swiftmac-get-pitch-range-code (value family)
"Get pitch-range code for specified VALUE and FAMILY."
(or family (setq family 'paul))
(if value
(aref (swiftmac-css-get-code-table family 'pitch-range)
value)
""))
;;; stress
;;; paul stress TODO
(let ((table (make-vector 10 "")))
(mapc
#'(lambda (setting)
(aset table
(cl-first setting)
(format " [[stress %s %s %s %s]] "
(cl-second setting)
(cl-third setting)
(cl-fourth setting)
(cl-fifth setting)
)))
'(
(0 1 1 0.1 0.1)
(1 1 1 10 .1)
(2 1 1 20 .2)
(3 1 1 30 .2)
(4 1 1 40 .3)
(5 1 1 50 .3)
(6 1 1 60 .3)
(7 1 1 70 .3)
(8 1 1 80 .3)
(9 1 1 90 .3)))
(swiftmac-css-set-code-table 'paul 'stress table))
(defun swiftmac-get-stress-code (value family)
(or family (setq family 'paul))
(if value
(aref (swiftmac-css-get-code-table family 'stress)
value)
""))
;;; richness
;;; paul richness TODO
(let ((table (make-vector 10 "")))
(swiftmac-css-set-code-table 'paul 'richness table))
(defun swiftmac-get-richness-code (value family)
(or family (setq family 'paul))
(if value
(aref (swiftmac-css-get-code-table family 'richness)
value)
""))
;;; swiftmac-define-voice-from-speech-style
(defun swiftmac-define-voice-from-speech-style (name style)
"Define NAME to be a swiftmac voice as specified by settings in STYLE."
(let* ((family(acss-family style))
(command
(concat
(swiftmac-get-family-code family)
(swiftmac-get-average-pitch-code (acss-average-pitch style) family)
(swiftmac-get-pitch-range-code (acss-pitch-range style) family)
(swiftmac-get-stress-code (acss-stress style) family)
(swiftmac-get-richness-code (acss-richness style) family))))
(swiftmac-define-voice name command)))
;;; Configurater
;;;###autoload
(defun swiftmac-configure-tts ()
"Configure TTS to use swiftmac."
(cl-declare (special tts-default-speech-rate
tts-default-voice swiftmac-default-speech-rate))
(setq tts-default-voice 'paul)
(fset 'tts-voice-defined-p 'swiftmac-voice-defined-p)
(fset 'tts-get-voice-command 'swiftmac-get-voice-command)
(fset 'tts-define-voice-from-speech-style 'swiftmac-define-voice-from-speech-style)
(setq tts-default-speech-rate swiftmac-default-speech-rate)
(set-default 'tts-default-speech-rate swiftmac-default-speech-rate)
(dtk-unicode-update-untouched-charsets
'(ascii latin-iso8859-1 latin-iso8859-15 latin-iso8859-9
eight-bit-graphic))
(setq emacspeak-play-program nil))
;;; tts-env for Mac:
(provide 'swiftmac-voices)