| 1 |
\input texinfo @c -*-texinfo-*- |
| 2 |
@c %**start of header |
| 3 |
@setfilename speech-dispatcher.info |
| 4 |
@settitle Speech Dispatcher |
| 5 |
@finalout |
| 6 |
@c @setchapternewpage odd |
| 7 |
@c %**end of header |
| 8 |
|
| 9 |
@syncodeindex pg cp |
| 10 |
@syncodeindex fn cp |
| 11 |
@syncodeindex vr cp |
| 12 |
|
| 13 |
@include version.texi |
| 14 |
|
| 15 |
@dircategory Sound |
| 16 |
@dircategory Development |
| 17 |
|
| 18 |
@direntry |
| 19 |
* Speech Dispatcher: (speech-dispatcher). Speech Dispatcher. |
| 20 |
@end direntry |
| 21 |
|
| 22 |
@titlepage |
| 23 |
@title Speech Dispatcher |
| 24 |
@subtitle Mastering the Babylon of TTS' |
| 25 |
@subtitle for Speech Dispatcher @value{VERSION} |
| 26 |
@author Tom@'a@v{s} Cerha <@email{cerha@@brailcom.org}> |
| 27 |
@author Hynek Hanke <@email{hanke@@volny.cz}> |
| 28 |
@author Milan Zamazal <@email{pdm@@brailcom.org}> |
| 29 |
|
| 30 |
@page |
| 31 |
@vskip 0pt plus 1filll |
| 32 |
|
| 33 |
This manual documents Speech Dispatcher, version @value{VERSION}. |
| 34 |
|
| 35 |
Copyright @copyright{} 2001, 2002, 2003, 2006, 2007, 2008 Brailcom, o.p.s. |
| 36 |
|
| 37 |
@quotation |
| 38 |
Permission is granted to copy, distribute and/or modify this document |
| 39 |
under the terms of the GNU Free Documentation License, Version 1.2 or |
| 40 |
any later version published by the Free Software Foundation; with no |
| 41 |
Invariant Sections, with no Front-Cover Texts and no Back-Cover Texts. |
| 42 |
A copy of the license is included in the section entitled ``GNU Free |
| 43 |
Documentation License.'' |
| 44 |
@end quotation |
| 45 |
|
| 46 |
You can also (at your option) distribute this manual under the GNU |
| 47 |
General Public License: |
| 48 |
|
| 49 |
@quotation |
| 50 |
Permission is granted to copy, distribute and/or modify this document |
| 51 |
under the terms of the GNU General Public License as published by the |
| 52 |
Free Software Foundation; either version 2 of the License, or (at your |
| 53 |
option) any later version. |
| 54 |
|
| 55 |
A copy of the license is included in the section entitled ``GNU |
| 56 |
General Public License'' |
| 57 |
@end quotation |
| 58 |
|
| 59 |
@end titlepage |
| 60 |
|
| 61 |
@summarycontents |
| 62 |
@contents |
| 63 |
|
| 64 |
@ifnottex |
| 65 |
@node Top, Introduction, (dir), (dir) |
| 66 |
@top Speech Dispatcher |
| 67 |
|
| 68 |
This manual documents Speech Dispatcher, version @value{VERSION}. |
| 69 |
|
| 70 |
Copyright @copyright{} 2001, 2002, 2003, 2006 Brailcom, o.p.s. |
| 71 |
|
| 72 |
@quotation |
| 73 |
Permission is granted to copy, distribute and/or modify this document |
| 74 |
under the terms of the GNU Free Documentation License, Version 1.2 or |
| 75 |
any later version published by the Free Software Foundation; with no |
| 76 |
Invariant Sections, with no Front-Cover Texts and no Back-Cover Texts. |
| 77 |
A copy of the license is included in the section entitled ``GNU Free |
| 78 |
Documentation License.'' |
| 79 |
@end quotation |
| 80 |
|
| 81 |
You can also (at your option) distribute this manual under the GNU |
| 82 |
General Public License: |
| 83 |
|
| 84 |
@quotation |
| 85 |
Permission is granted to copy, distribute and/or modify this document |
| 86 |
under the terms of the GNU General Public License as published by the |
| 87 |
Free Software Foundation; either version 2 of the License, or (at your |
| 88 |
option) any later version. |
| 89 |
|
| 90 |
A copy of the license is included in the section entitled ``GNU |
| 91 |
General Public License'' |
| 92 |
@end quotation |
| 93 |
|
| 94 |
@end ifnottex |
| 95 |
|
| 96 |
@ifhtml |
| 97 |
@heading Menu |
| 98 |
@end ifhtml |
| 99 |
|
| 100 |
@menu |
| 101 |
* Introduction:: What is Speech Dispatcher. |
| 102 |
* User's Documentation:: Usage, Configuration... |
| 103 |
* Technical Specifications:: |
| 104 |
* Client Programming:: Documentation for application developers. |
| 105 |
* Server Programming:: Documentation for project contributors. |
| 106 |
|
| 107 |
* Download and Contact:: How to get Speech Dispatcher and how to contact us |
| 108 |
* Reporting Bugs:: How to report a bug |
| 109 |
* How You Can Help:: What is needed |
| 110 |
|
| 111 |
* Appendices:: |
| 112 |
* GNU General Public License:: Copying conditions for Speech Dispatcher |
| 113 |
* GNU Free Documentation License:: Copying conditions for this manual |
| 114 |
|
| 115 |
* Index of Concepts:: |
| 116 |
@end menu |
| 117 |
|
| 118 |
@node Introduction, User's Documentation, Top, Top |
| 119 |
@chapter Introduction |
| 120 |
|
| 121 |
@menu |
| 122 |
* Motivation:: Why Speech Dispatcher? |
| 123 |
* Basic Design:: How does it work? |
| 124 |
* Features Overview:: What are the assets? |
| 125 |
* Current State:: What is done? |
| 126 |
@end menu |
| 127 |
|
| 128 |
@node Motivation, Basic Design, Introduction, Introduction |
| 129 |
@section Motivation |
| 130 |
@cindex Basic ideas, Motivation |
| 131 |
@cindex Philosophy |
| 132 |
|
| 133 |
Speech Dispatcher is a device independent layer for speech synthesis |
| 134 |
that provides a common easy to use interface for both client |
| 135 |
applications (programs that want to speak) and for software |
| 136 |
synthesizers (programs actually able to convert text to speech). |
| 137 |
|
| 138 |
High quality speech synthesis is now commonly available both as |
| 139 |
propriatary and Free Software solutions. It has a wide field of |
| 140 |
possible uses from educational software to specialized systems, |
| 141 |
e.g. in hospitals or laboratories. It is also a key compensation tool |
| 142 |
for the visually impaired users. For them, it is one of the two |
| 143 |
possible ways of getting output from a computer (the second one being |
| 144 |
a Braille display). |
| 145 |
|
| 146 |
The various speech synthesizers are quite different, both in their |
| 147 |
interfaces and capabilities. Thus a general common interface is needed |
| 148 |
so that the client application programmers have an easy way to use |
| 149 |
software speech synthesis and don't have to care about peculiar |
| 150 |
details of the various synthesizers. |
| 151 |
|
| 152 |
The absence of such a common and standardized interface and thus the |
| 153 |
difficulty for programmers to use software speech synthesis has |
| 154 |
been a major reason why the potential of speech synthesis technology |
| 155 |
is still not fully exploited. |
| 156 |
|
| 157 |
Ideally, there would be little distinction for applications whether |
| 158 |
they output messages on the screen or via speech. Speech Dispatcher |
| 159 |
can be compared to what a GUI toolkit is for the graphical |
| 160 |
interface. Not only does it provide an easy to use interface, some |
| 161 |
kind of theming and configuration mechanisms, but also it takes care |
| 162 |
of some of the issues inherent with this particular mode of output, |
| 163 |
such as the need for speech message serialization and interaction with |
| 164 |
the audio subsystem. |
| 165 |
|
| 166 |
@node Basic Design, Features Overview, Motivation, Introduction |
| 167 |
@section Design |
| 168 |
@cindex Design |
| 169 |
|
| 170 |
@heading Current Design |
| 171 |
The communication between all applications and synthesizers, when |
| 172 |
implemented directly, is a mess. For this purpose, we wanted |
| 173 |
Speech Dispatcher to be a layer separating applications and |
| 174 |
synthesizers so that applications wouldn't have to care about |
| 175 |
synthesizers and synthesizers wouldn't have to care about interaction |
| 176 |
with applications. |
| 177 |
|
| 178 |
We decided we would implement Speech Dispatcher as a server receiving |
| 179 |
commands from applications over a protocol called @code{SSIP}, |
| 180 |
parsing them if needed, and calling the appropriate functions |
| 181 |
of output modules communicating with the different synthesizers. |
| 182 |
These output modules are implemented as plug-ins, so that the user |
| 183 |
can just load a new module if he wants to use a new synthesizer. |
| 184 |
|
| 185 |
Each client (application that wants to speak) opens a socket |
| 186 |
connection to Speech Dispatcher and calls functions like say(), |
| 187 |
stop(), and pause() provided by a library implementing the protocol. |
| 188 |
This shared library is still on the client side and sends Speech |
| 189 |
Dispatcher SSIP commands over the socket. When the messages arrive at |
| 190 |
Speech Dispatcher, it parses them, reads the text that should be said |
| 191 |
and puts it in one of several queues according to the priority of the |
| 192 |
message and other criteria. It then decides when, with which |
| 193 |
parameters (set up by the client and the user), and on which |
| 194 |
synthesizer it will say the message. These requests are handled by the |
| 195 |
output plug-ins (output modules) for different hardware and software |
| 196 |
synthesizers and then said aloud. |
| 197 |
|
| 198 |
@image{/usr/share/doc/speech-dispatcher/architecture,155mm,,Speech Dispatcher architecture} |
| 199 |
|
| 200 |
See also the detailed description @ref{Client Programming} interfaces, and |
| 201 |
@ref{Server Programming} documentation. |
| 202 |
|
| 203 |
@heading Future Design |
| 204 |
|
| 205 |
Speech Dispatcher currently mixes two important features: common |
| 206 |
low-level interface to multiple speech synthesizers and message |
| 207 |
management (including priorities and history). This became even more |
| 208 |
evident when we started thinking about handling messages intended for |
| 209 |
output on braille devices. Such messages of course need to be |
| 210 |
synchronized with speech messages and there is little reason why the |
| 211 |
accessibility tools should send the same message twice for these two |
| 212 |
different kinds of output used by blind people (often simultaneously). |
| 213 |
Outside the world of accessibility, applications also want to either |
| 214 |
have full control over the sound (bypass prioritisation) or to only |
| 215 |
retrieve the synthesized data, but not play them immediately. |
| 216 |
|
| 217 |
We want to eventually split Speech Dispatcher into two independent |
| 218 |
components: one providing a low-level interface to speech synthesis |
| 219 |
drivers, which we now call TTS API Provider and is already largely |
| 220 |
implemented in the Free(b)Soft project, and the second doing message |
| 221 |
management, called Message Dispatcher. This will allow Message |
| 222 |
Dispatcher to also output on Braille as well as to use the TTS API |
| 223 |
Provider separately. |
| 224 |
|
| 225 |
From implementation point of view, an opportunity for new design based |
| 226 |
on our previous experiences allowed us to remove several bottlenecks |
| 227 |
for speed (responsiveness), ease of use and ease of implementation of |
| 228 |
extensions (particularly output modules for new synthesizers). From |
| 229 |
the architecture point of view and possibilities for new developments, |
| 230 |
we are entirely convinced that both the new design in general and the |
| 231 |
inner design of the new components is much better. |
| 232 |
|
| 233 |
While a good API and its implementation for Braille are already |
| 234 |
existent in the form of BrlAPI, the API for speech is now under |
| 235 |
development. Please see another architecture diagram showing how we |
| 236 |
imagine Message Dispatcher in the future. |
| 237 |
|
| 238 |
@image{/usr/share/doc/speech-dispatcher/architecture-future,155mm,,Speech Dispatcher architecture} |
| 239 |
|
| 240 |
References: |
| 241 |
@uref{http://www.freebsoft.org/tts-api/} |
| 242 |
@uref{http://www.freebsoft.org/tts-api-provider/} |
| 243 |
|
| 244 |
@node Features Overview, Current State, Basic Design, Introduction |
| 245 |
@section Features Overview |
| 246 |
Speech Dispatcher from user's point of view: |
| 247 |
|
| 248 |
@itemize @bullet |
| 249 |
@item ability to freely combine applications with your favorite synthesizer |
| 250 |
@item message synchronization and coordination |
| 251 |
@item less time devoted to configuration of applications |
| 252 |
@end itemize |
| 253 |
|
| 254 |
Speech Dispatcher from application programmers's point of view: |
| 255 |
|
| 256 |
@itemize @bullet |
| 257 |
@item easy way to make your applications speak |
| 258 |
@item common interface to different synthesizers |
| 259 |
@item higher level synchronization of messages (priorities) |
| 260 |
@item no need to take care about configuration of voice(s) |
| 261 |
@end itemize |
| 262 |
|
| 263 |
@node Current State, , Features Overview, Introduction |
| 264 |
@section Current State |
| 265 |
@cindex Synthesizers |
| 266 |
@cindex Other programs |
| 267 |
|
| 268 |
In this version, most of the features of Speech Dispatcher are |
| 269 |
implemented and we believe it is now useful for applications as a |
| 270 |
device independent Text-to-Speech layer and an accessibility message |
| 271 |
coordination layer. |
| 272 |
|
| 273 |
Currently, one of the most advanced applications that works with |
| 274 |
Speech Dispatcher is @code{speechd-el}. This is a client for Emacs, |
| 275 |
targeted primarily for blind people. It is similar to Emacspeak, |
| 276 |
however the two take a bit different approach and serve different user |
| 277 |
needs. You can find speechd-el on |
| 278 |
@uref{http://www.freebsoft.org/speechd-el/}. speechd-el provides |
| 279 |
speech output when using nearly any GNU/Linux text interface, like |
| 280 |
editing text, reading email, browsing the web, etc. |
| 281 |
|
| 282 |
Orca, the primary screen reader for the Gnome Desktop, supports Speech |
| 283 |
Dispatcher directly since its version 2.19.0. See |
| 284 |
@uref{http://live.gnome.org/Orca/SpeechDispatcher} for more |
| 285 |
information. |
| 286 |
|
| 287 |
We also provide a shared C library, a Python library, a Java, Guile |
| 288 |
and a Common Lisp libraries that implement the SSIP functions of |
| 289 |
Speech Dispatcher in higher level interfaces. A golang interface is also |
| 290 |
available on @uref{https://github.com/ilyapashuk/go-speechd}. Writing client |
| 291 |
applications in these languages should be quite easy. |
| 292 |
|
| 293 |
On the synthesis side, there is good support for Festival, eSpeak, |
| 294 |
Flite, Cicero, IBM TTS, MBROLA, Epos, Dectalk software, Cepstral Swift |
| 295 |
and others. See @xref{Supported Modules}. |
| 296 |
|
| 297 |
We decided not to interface the simple hardware speech devices as they |
| 298 |
don't support synchronization and therefore cause serious problems |
| 299 |
when handling multiple messages. Also they are not extensible, they |
| 300 |
are usually expensive and often hard to support. Today's computers are |
| 301 |
fast enough to perform software speech synthesis and Festival is a |
| 302 |
great example. |
| 303 |
|
| 304 |
@node User's Documentation, Technical Specifications, Introduction, Top |
| 305 |
@chapter User's Documentation |
| 306 |
|
| 307 |
@menu |
| 308 |
* Installation:: How to get it installed in the best way. |
| 309 |
* Running:: The different ways to start it. |
| 310 |
* Troubleshooting:: What to do if something doesn't work... |
| 311 |
* Configuration:: How to configure Speech Dispatcher. |
| 312 |
* Tools:: What tools come with Speech Dispatcher. |
| 313 |
* Synthesis Output Modules:: Drivers for different synthesizers. |
| 314 |
* Security:: Security mechanisms and restrictions. |
| 315 |
@end menu |
| 316 |
|
| 317 |
@node Installation, Running, User's Documentation, User's Documentation |
| 318 |
@section Installation |
| 319 |
|
| 320 |
This part only deals with the general aspects of installing |
| 321 |
Speech Dispatcher. If you are compiling from source code (distribution |
| 322 |
tarball or git), please refer to the file @file{INSTALL} in your |
| 323 |
source tree. |
| 324 |
|
| 325 |
@subsection The requirements |
| 326 |
|
| 327 |
You will need these components to run Speech Dispatcher: |
| 328 |
@itemize |
| 329 |
@item glib 2.0 (@uref{http://www.gtk.org}) |
| 330 |
@item libdotconf 1.3 (@uref{http://github.com/williamh/dotconf}) |
| 331 |
@item pthreads |
| 332 |
@end itemize |
| 333 |
|
| 334 |
We recommend to also install these packages: |
| 335 |
@itemize |
| 336 |
@item Festival (@uref{http://www.cstr.ed.ac.uk/projects/festival/}) |
| 337 |
@item festival-freebsoft-utils 0.3+ (@uref{http://www.freebsoft.org/festival-freebsoft-utils}) |
| 338 |
@item Sound icons library @* (@uref{http://www.freebsoft.org/pub/projects/sound-icons/sound-icons-0.1.tar.gz}) |
| 339 |
@end itemize |
| 340 |
|
| 341 |
@subsection Recommended installation procedure |
| 342 |
|
| 343 |
@itemize |
| 344 |
|
| 345 |
@item Install your software synthesizer |
| 346 |
|
| 347 |
Although we highly recommend to use Festival for its excellent |
| 348 |
extensibility, good quality voices, good responsiveness and best |
| 349 |
support in Speech Dispatcher, you might want to start with eSpeak, a |
| 350 |
lightweight multi-lingual feature-complete synthesizer, to get all the |
| 351 |
key components working and perhaps only then switch to |
| 352 |
Festival. Installation of eSpeak should be easier and the default |
| 353 |
configuration of Speech Dispatcher is set up for eSpeak for this |
| 354 |
reason. |
| 355 |
|
| 356 |
You can of course also start with Epos or any other supported synthesizer. |
| 357 |
|
| 358 |
@item Make sure your synthesizer works |
| 359 |
|
| 360 |
There is usually a way to test if the installation of your speech |
| 361 |
synthesizer works. For eSpeak run @code{espeak "test"}, for Flite run |
| 362 |
@code{flite -t "Hello!"} and hear the speech. For Festival run |
| 363 |
@code{festival} and type in |
| 364 |
|
| 365 |
@example |
| 366 |
(SayText "Hello!") |
| 367 |
(quit) |
| 368 |
@end example |
| 369 |
|
| 370 |
@item Install Speech Dispatcher |
| 371 |
|
| 372 |
Install the packages for Speech Dispatcher from your distribution or |
| 373 |
download the source tarball (or git) from |
| 374 |
@url{http://www.freebsoft.org/speechd} and follow the instructions in |
| 375 |
the file @code{INSTALL} in the source tree. |
| 376 |
|
| 377 |
@item Configure Speech Dispatcher |
| 378 |
|
| 379 |
You can skip this step in most cases. If you however want to setup |
| 380 |
your own configuration of the Dispatchers default values, the easiest |
| 381 |
way to do so is through the @code{spd-conf} configuration script. It |
| 382 |
will guide you through the basic configuration. It will also |
| 383 |
subsequently perform some diagnostics tests and offer some limited |
| 384 |
help with troubleshooting. Just execute |
| 385 |
|
| 386 |
@example |
| 387 |
spd-conf |
| 388 |
@end example |
| 389 |
|
| 390 |
under an ordinary user or system user like 'speech-dispatcher' |
| 391 |
depending on whether you like to setup Speech Dispatcher as user or |
| 392 |
system service respectively. You might also want to explore the |
| 393 |
offered options or run some of its subsystems manually, type |
| 394 |
@code{spd-conf -h} for help. |
| 395 |
|
| 396 |
If you do not want to use this script, it doesn't work in your case |
| 397 |
or it doesn't provide enough configuration flexibility, please |
| 398 |
continue as described below and/or in @xref{Running Under Ordinary Users}. |
| 399 |
|
| 400 |
@item Test Speech Dispatcher |
| 401 |
|
| 402 |
The simplest way to test Speech Dispatcher is through |
| 403 |
@code{spd-conf -d} or through the @code{spd-say} tool. |
| 404 |
|
| 405 |
Example: |
| 406 |
@example |
| 407 |
spd-conf -d |
| 408 |
spd-say "Hello!" |
| 409 |
spd-say -l cs -r 90 "Ahoj" |
| 410 |
@end example |
| 411 |
|
| 412 |
If you don't hear anything, please @xref{Troubleshooting}. |
| 413 |
|
| 414 |
@end itemize |
| 415 |
|
| 416 |
@subsection How to use eSpeak NG or eSpeak with MBROLA |
| 417 |
|
| 418 |
Please follow the guidelines at |
| 419 |
@url{https://github.com/espeak-ng/espeak-ng/blob/master/docs/mbrola.md} |
| 420 |
(resp. @url{http://espeak.sourceforge.net/mbrola.html}) |
| 421 |
for installing eSpeak NG (resp. eSpeak) with a set of MBROLA voices that you |
| 422 |
want to use. |
| 423 |
|
| 424 |
Check the @file{modules/espeak-ng-mbrola-generic.conf} |
| 425 |
(resp. @file{modules/espeak-mbrola-generic.conf}) configuration files for the |
| 426 |
@code{AddVoice} lines. If a line for any of the voices you have installed |
| 427 |
(and it is supported by your version of eSpeak NG (resp. eSpeak), |
| 428 |
e.g. @code{ls /usr/share/espeak-ng-data/voices/mb/mb-*} |
| 429 |
(resp. @code{ls /usr/share/espeak-data/voices/mb/mb-*})) |
| 430 |
is not contained here, please add it. Check if @code{GenericExecuteString} |
| 431 |
contains the correct name of your mbrola binary and correct path to its voice |
| 432 |
database. |
| 433 |
|
| 434 |
Restart speech-dispatcher and in your client, select |
| 435 |
@code{espeak-ng-mbrola-generic} (resp. @code{espeak-mbrola-generic}) as your |
| 436 |
output module, or test it with the following command |
| 437 |
|
| 438 |
@example |
| 439 |
spd-say -o espeak-ng-mbrola-generic -l cs Testing |
| 440 |
@end example |
| 441 |
|
| 442 |
(resp. |
| 443 |
@example |
| 444 |
spd-say -o espeak-mbrola-generic -l cs Testing |
| 445 |
@end example |
| 446 |
) |
| 447 |
|
| 448 |
@node Running, Troubleshooting, Installation, User's Documentation |
| 449 |
@section Running |
| 450 |
|
| 451 |
Speech Dispatcher is normally executed on a per-user basis. This |
| 452 |
provides more flexibility in user configuration, access rights and is |
| 453 |
essential in any environment where multiple people use the computer at |
| 454 |
the same time. It used to be possible to run Speech Dispatcher as a system |
| 455 |
service under a special user (and still is, with some limitations), but |
| 456 |
this mode of execution is strongly discouraged. |
| 457 |
|
| 458 |
@menu |
| 459 |
* Running Under Ordinary Users:: |
| 460 |
* Running in a Custom Setup:: |
| 461 |
* Setting Communication Method:: |
| 462 |
@end menu |
| 463 |
|
| 464 |
@node Running Under Ordinary Users, Running in a Custom Setup, Running, Running |
| 465 |
@subsection Running Under Ordinary Users |
| 466 |
|
| 467 |
No special provisions need to be done to run Speech Dispatcher under |
| 468 |
the current user. The Speech Dispatcher process will use (or create) a |
| 469 |
@file{~/.cache/speech-dispatcher/} directory for its purposes (logging, |
| 470 |
pidfile). |
| 471 |
|
| 472 |
Optionally, a user can place his own configuration file in |
| 473 |
@file{~/.config/speech-dispatcher/speechd.conf} and it will be |
| 474 |
automatically loaded by Speech Dispatcher. The preferred way to do so |
| 475 |
is via the @code{spd-conf} configuration command. If this user |
| 476 |
configuration file is not found, Speech Dispatcher will simply use the |
| 477 |
system wide configuration file (e.g. in |
| 478 |
@file{/etc/speech-dispatcher/speechd.conf}). |
| 479 |
|
| 480 |
@example |
| 481 |
# speech-dispatcher |
| 482 |
# spd-say test |
| 483 |
@end example |
| 484 |
|
| 485 |
@node Running in a Custom Setup, Setting Communication Method, Running Under Ordinary Users, Running |
| 486 |
@subsection Running in a Custom Setup |
| 487 |
|
| 488 |
Speech Dispatcher can be run in any other setup of executing users, port |
| 489 |
numbers and system paths as well. The path to configuration, pidfile and |
| 490 |
logfiles can be specified separately via compilation flags, |
| 491 |
configuration file options or command line options in this ascending |
| 492 |
order of their priority. |
| 493 |
|
| 494 |
This way can also be used to start Speech Dispatcher as a system wide |
| 495 |
service from /etc/init.d/ , although this approach is now discouraged. |
| 496 |
|
| 497 |
@node Setting Communication Method, , Running in a Custom Setup, Running |
| 498 |
@subsection Setting Communication Method |
| 499 |
|
| 500 |
Currently, two different methods are supported for communication |
| 501 |
between the server and its clients. |
| 502 |
|
| 503 |
For local communication, it's preferred to use @emph{Unix sockets}, |
| 504 |
where the communication takes place over a Unix socket with its |
| 505 |
driving file located by default in the user's runtime directory as |
| 506 |
@code{XDG_RUNTIME_DIR/speech-dispatcher/speechd.sock}. In this way, there can be no |
| 507 |
conflict between different user sessions using different Speech |
| 508 |
Dispatchers in the same system. By default, permissions are set in |
| 509 |
such a way, that only the same user who started the server can access |
| 510 |
it, and communication is hidden to all other users. |
| 511 |
|
| 512 |
The other supported mechanism is @emph{Inet sockets}. The server will |
| 513 |
thus run on a given port, which can be made accessible either localy |
| 514 |
or to other machines on the network as well. This is very useful in a |
| 515 |
network setup. Be however aware that while using Inet sockets, both |
| 516 |
parties (server and clients) must first agree on the communication |
| 517 |
port number to use, which can create a lot of confusion in a setup |
| 518 |
where multiple instances of the server serve multiple different users. |
| 519 |
Also, since there is currently no authentication mechanism, during |
| 520 |
Inet socket communication, the server will make no distinction between |
| 521 |
the different users connecting to it. The default port is 6560 as set |
| 522 |
in the server configuration. |
| 523 |
|
| 524 |
Client applications will respect the @emph{SPEECHD_ADDRESS} environment |
| 525 |
variable. The method ('@code{unix_socket}' or '@code{inet_socket}') |
| 526 |
is optionally followed by it's parameters separated by a colon. |
| 527 |
For an exact description, please @xref{Address specification}. |
| 528 |
|
| 529 |
An example of launching Speech Dispatcher using unix_sockets |
| 530 |
for communication on a non-standard destination and subsequently |
| 531 |
using spd-say to speak a message: |
| 532 |
|
| 533 |
@example |
| 534 |
killall -u `whoami` speech-dispatcher |
| 535 |
speech-dispatcher -c unix_socket -S /tmp/my.sock |
| 536 |
SPEECHD_ADDRESS=unix_socket:/tmp/my.sock spd-say "test" |
| 537 |
@end example |
| 538 |
|
| 539 |
@node Troubleshooting, Configuration, Running, User's Documentation |
| 540 |
@section Troubleshooting |
| 541 |
|
| 542 |
If you are experiencing problems when running Speech Dispatcher, please: |
| 543 |
|
| 544 |
@itemize |
| 545 |
|
| 546 |
@item |
| 547 |
Use @code{spd-conf} to run diagnostics: |
| 548 |
|
| 549 |
@example |
| 550 |
spd-conf -d |
| 551 |
@end example |
| 552 |
|
| 553 |
@item |
| 554 |
Check the appropriate logfile in |
| 555 |
@file{~/.cache/speech-dispatcher/log/speech-dispatcher.log} for user Speech |
| 556 |
Dispatcher or in @file{/var/log/speech-dispatcher/speech-dispatcher.log}. Look |
| 557 |
for lines containing the string 'ERROR' and their surrounding |
| 558 |
contents. If you hear no speech, restart Speech Dispatcher and look |
| 559 |
near the end of the log file -- before any attempts for synthesis of |
| 560 |
any message. Usually, if something goes wrong with the initialization |
| 561 |
of the output modules, a textual description of the problem and a |
| 562 |
suggested solution can be found in the log file. |
| 563 |
|
| 564 |
@item |
| 565 |
If this doesn't reveal the problem, please run |
| 566 |
@example |
| 567 |
spd-conf -D |
| 568 |
@end example |
| 569 |
|
| 570 |
Which will generate a very detailed logfile archive |
| 571 |
which you can examine yourself or send to us with |
| 572 |
a request for help. |
| 573 |
|
| 574 |
@item |
| 575 |
You can also try to say some message directly through the utility |
| 576 |
@code{spd-say}. |
| 577 |
|
| 578 |
Example: |
| 579 |
@example |
| 580 |
spd-say "Hello, does it work?" |
| 581 |
spd-say --language=cs --rate=20 "Everything ok?" |
| 582 |
@end example |
| 583 |
|
| 584 |
@item |
| 585 |
Check if your configuration files (speechd.conf, modules/*.conf) |
| 586 |
are correct (some uninstalled synthesizer specified as the default, |
| 587 |
wrong values for default voice parameters etc.) |
| 588 |
|
| 589 |
@item |
| 590 |
There is a know problem in some versions of Festival. Please make sure |
| 591 |
that Festival server_access_list configuration variable and your |
| 592 |
/etc/hosts.conf are set properly. server_access_list must contain the |
| 593 |
symbolic name of your machine and this name must be defined in |
| 594 |
/etc/hosts.conf and point to your IP address. You can test if this is |
| 595 |
set correctly by trying to connect to the port Festival server is |
| 596 |
running on via an ordinary telnet (by default like this: @code{telnet |
| 597 |
localhost 1314}). If you are not rejected, it works. |
| 598 |
|
| 599 |
@item |
| 600 |
One can connect to the speech-dispatcher server by hand by using |
| 601 |
@example |
| 602 |
socat $XDG_RUNTIME_DIR/speech-dispatcher/speechd.sock,crlf STDIO |
| 603 |
@end example |
| 604 |
|
| 605 |
@end itemize |
| 606 |
|
| 607 |
@node Configuration, Tools, Troubleshooting, User's Documentation |
| 608 |
@section Configuration |
| 609 |
@cindex configuration |
| 610 |
@cindex default values |
| 611 |
|
| 612 |
Speech Dispatcher can be configured on several different levels. You |
| 613 |
can configure the global settings through the server configuration |
| 614 |
file, which can be placed either in the Speech Dispatcher default |
| 615 |
configuration system path like /etc/speech-dispatcher/ or in your home |
| 616 |
directory in @file{~/.config/speech-dispatcher/}. There is also support for |
| 617 |
per-client configuration, this is, specifying different default values |
| 618 |
for different client applications. |
| 619 |
|
| 620 |
Furthermore, applications often come with their own means of configuring |
| 621 |
speech related settings. Please see the documentation of your |
| 622 |
application for details about application specific configuration. |
| 623 |
|
| 624 |
@menu |
| 625 |
* Configuration file syntax:: Basic rules. |
| 626 |
* Configuration options:: What to configure. |
| 627 |
* Symbols processing configuration:: How text is processed with symbols. |
| 628 |
* Audio Output Configuration:: How to switch to ALSA, Pulse... |
| 629 |
* Client Specific Configuration:: Specific default values for applications. |
| 630 |
* Output Modules Configuration:: Adding and customizing output modules. |
| 631 |
* Log Levels:: Description of log levels. |
| 632 |
@end menu |
| 633 |
|
| 634 |
@node Configuration file syntax, Configuration options, Configuration, Configuration |
| 635 |
@subsection Configuration file syntax |
| 636 |
|
| 637 |
We use the DotConf library to read a permanent text-file based |
| 638 |
configuration, so the syntax might be familiar to many users. |
| 639 |
|
| 640 |
Each of the string constants, if not otherwise stated differently, |
| 641 |
should be encoded in UTF-8. The option names use only the |
| 642 |
standard ASCII charset restricted to upper- and lowercase characters |
| 643 |
(@code{a}, @code{b}), dashes (@code{-}) and underscores @code{_}. |
| 644 |
|
| 645 |
Comments and temporarily inactive options begin with @code{#}. |
| 646 |
If such an option should be turned on, just remove the comment |
| 647 |
character and set it to the desired value. |
| 648 |
@example |
| 649 |
# this is a comment |
| 650 |
# InactiveOption "this option is turned off" |
| 651 |
@end example |
| 652 |
|
| 653 |
Strings are enclosed in doublequotes. |
| 654 |
@example |
| 655 |
LogFile "/var/log/speech-dispatcher.log" |
| 656 |
@end example |
| 657 |
|
| 658 |
Numbers are written without any quotes. |
| 659 |
@example |
| 660 |
Port 6560 |
| 661 |
@end example |
| 662 |
|
| 663 |
Boolean values use On (for true) and Off (for false). |
| 664 |
@example |
| 665 |
Debug Off |
| 666 |
@end example |
| 667 |
|
| 668 |
@node Configuration options, Symbols processing configuration, Configuration file syntax, Configuration |
| 669 |
@subsection Configuration options |
| 670 |
|
| 671 |
All available options are documented directly in the file and examples |
| 672 |
are provided. Most of the options are set to their default value and |
| 673 |
commented out. If you want to change them, just change the value and |
| 674 |
remove the comment symbol @code{#}. |
| 675 |
|
| 676 |
@node Symbols processing configuration, Audio Output Configuration, Configuration options, Configuration |
| 677 |
@subsection Symbols processing configuration |
| 678 |
|
| 679 |
Speech Dispatcher preprocesses text before giving it to output modules, to |
| 680 |
support ample sets of characters (including emojis) and provide a homogeneous |
| 681 |
behavior. |
| 682 |
|
| 683 |
This is configured through the use of the @code{SymbolsPreprocFile} lines in |
| 684 |
the main configuration file, which load a series of dictionaries. When text is |
| 685 |
preprocessed, each dictionary is applied, in the order of appearance in the |
| 686 |
configuration file. The principle is to first apply quite generic |
| 687 |
transformations (e.g. various unicode fonts forms) before applying more specific |
| 688 |
transformations (e.g. abbreviations). |
| 689 |
|
| 690 |
The dictionaries are localized, to provide translation adapted to each |
| 691 |
language. They can be found in locale-named directories in |
| 692 |
@file{/usr/share/speech-dispatcher/locale/} |
| 693 |
Speech-dispatcher tries to open them from most specific locales to least |
| 694 |
specific: for instance for brazilian speech, it will first try to load from |
| 695 |
@file{pt_BR}, then from @file{pt}, before falling back to @file{base}. |
| 696 |
|
| 697 |
Users can override the dictionaries by copying a dictionary into their |
| 698 |
@file{~/.config/speech-dispatcher/locale/} directory, or even locale-named |
| 699 |
subdirectories of it, and modifying them at will. They can also add |
| 700 |
@code{SymbolsPreprocFile} in the configuration file to add their own dictionary |
| 701 |
files along the series, before, after or among the existing dictionaries. |
| 702 |
|
| 703 |
@node Audio Output Configuration, Client Specific Configuration, Symbols processing configuration, Configuration |
| 704 |
@subsection Audio Output Configuration |
| 705 |
|
| 706 |
Audio output method (ALSA, Pulse etc.) can be configured centrally |
| 707 |
from the main configuration file @code{speechd.conf}. The option |
| 708 |
@code{AudioOutputMethod} selects the desired audio method and further |
| 709 |
options labeled as @code{AudioALSA...} or @code{AudioPulse...} provide |
| 710 |
a more detailed configuration of the given audio output method. |
| 711 |
|
| 712 |
It is possible to use a list of preferred audio output methods, |
| 713 |
in which case each output module attempts to use the first available |
| 714 |
in the given order. |
| 715 |
|
| 716 |
The example below prefers Pulse Audio, but will use ALSA if unable |
| 717 |
to connect to Pulse: |
| 718 |
@example |
| 719 |
AudioOutputMethod "pulse,alsa" |
| 720 |
@end example |
| 721 |
|
| 722 |
Please note however that some more simple output modules or |
| 723 |
synthesizers, like the generic output module, do not respect these |
| 724 |
settings and use their own means of audio output which can't be |
| 725 |
influenced this way. On the other hand, the fallback dummy output |
| 726 |
module tries to use any available means of audio output to deliver its |
| 727 |
error message. |
| 728 |
|
| 729 |
The @emph{SPEECHD_PLUGIN_DIR} environment variable allows to specify which |
| 730 |
directory the audio modules should be loaded from. |
| 731 |
|
| 732 |
@node Client Specific Configuration, Output Modules Configuration, Audio Output Configuration, Configuration |
| 733 |
@subsection Client Specific Configuration |
| 734 |
|
| 735 |
It is possible to automatically set different default values of speech |
| 736 |
parameters (e.g. rate, volume, punctuation, default voice...) for |
| 737 |
different applications that connect to Speech Dispatcher. This is |
| 738 |
especially useful for simple applications that have no parameter |
| 739 |
setting capabilities themselves or they don't support a parameter |
| 740 |
setting you wish to change (e.g. language). |
| 741 |
|
| 742 |
Using the commands @code{BeginClient "IDENTIFICATION"} and |
| 743 |
@code{EndClient} it is possible to open and close a section of |
| 744 |
parameter settings that only affects those client applications that |
| 745 |
identify themselves to Speech Dispatcher under the specific |
| 746 |
identification code which is matched against the string |
| 747 |
@code{IDENTIFICATION}. It is possible to use wildcards ('*' matches |
| 748 |
any number of characters and '?' matches exactly one character) in the |
| 749 |
string @code{IDENTIFICATION}. |
| 750 |
|
| 751 |
The identification code normally consists of 3 parts: |
| 752 |
@code{user:application:connection}. @code{user} is the username of the |
| 753 |
one who started the application, @code{application} is the name of the |
| 754 |
application (usually the name of the binary for it) and |
| 755 |
@code{connection} is a name for the connection (one application might |
| 756 |
use more connections for different purposes). |
| 757 |
|
| 758 |
An example is provided in @code{/etc/speech-dispatcher/speechd.conf} |
| 759 |
(see the line @code{Include "clients/emacs.conf"} and |
| 760 |
@code{/etc/speech-dispatcher/clients/emacs.conf}. |
| 761 |
|
| 762 |
@node Output Modules Configuration, Log Levels, Client Specific Configuration, Configuration |
| 763 |
@subsection Output Modules Configuration |
| 764 |
|
| 765 |
Each user should turn on at least one output module in his |
| 766 |
configuration, if he wants Speech Dispatcher to produce |
| 767 |
any sound output. If no output module is loaded, Speech Dispatcher |
| 768 |
will start, log messages into history and communicate with clients, |
| 769 |
but no sound is produced. |
| 770 |
|
| 771 |
Each output module has an |
| 772 |
``AddModule'' line in |
| 773 |
@file{speech-dispatcher/speechd.conf}. Additionally, each output |
| 774 |
module can have its own configuration file. |
| 775 |
|
| 776 |
The audio output is handled by the output modules themselves, so this |
| 777 |
can be switched in their own configuration files under |
| 778 |
@code{etc/speech-dispatcher/modules/}. Users can also set their own |
| 779 |
configuration files in @code{~/.config/speech-dispatcher/modules/}. |
| 780 |
|
| 781 |
@menu |
| 782 |
* Loading Modules in speechd.conf:: |
| 783 |
* Configuration files of output modules:: |
| 784 |
* Configuration of the Generic Output Module:: |
| 785 |
@end menu |
| 786 |
|
| 787 |
@node Loading Modules in speechd.conf, Configuration files of output modules, Output Modules Configuration, Output Modules Configuration |
| 788 |
@subsubsection Loading Modules in speechd.conf |
| 789 |
|
| 790 |
@anchor{AddModule} |
| 791 |
Each module that should be run when Speech Dispatcher starts must be loaded |
| 792 |
by the @code{AddModule} command in the configuration. Note that you can load |
| 793 |
one binary module multiple times under different names with different |
| 794 |
configurations. This is especially useful for loading the generic output |
| 795 |
module. @xref{Configuration of the Generic Output Module}. |
| 796 |
|
| 797 |
@example |
| 798 |
AddModule "@var{module_name}" "@var{module_binary}" "@var{module_config}" |
| 799 |
@end example |
| 800 |
|
| 801 |
@var{module_name} is the name of the output module. |
| 802 |
|
| 803 |
@var{module_binary} is the name of the binary executable |
| 804 |
of this output module. It can be either absolute or relative |
| 805 |
to @file{libexec/speech-dispatcher-modules/}. |
| 806 |
|
| 807 |
@var{module_config} is the file where the configuration for |
| 808 |
this output module is stored. It can be either absolute or relative |
| 809 |
to @file{etc/speech-dispatcher/modules/}. This parameter is optional. |
| 810 |
|
| 811 |
@node Configuration files of output modules, Configuration of the Generic Output Module, Loading Modules in speechd.conf, Output Modules Configuration |
| 812 |
@subsubsection Configuration Files of Output Modules |
| 813 |
|
| 814 |
Each output module is different and therefore has different |
| 815 |
configuration options. Please look at the comments in its |
| 816 |
configuration file for a detailed description. However, there are |
| 817 |
several options which are common for some output modules. Here is a |
| 818 |
short overview of them. |
| 819 |
|
| 820 |
@itemize |
| 821 |
@item AddVoice "@var{language}" "@var{symbolicname}" "@var{name}" |
| 822 |
@anchor{AddVoice} |
| 823 |
|
| 824 |
Each output module provides some voices and sometimes it even supports |
| 825 |
different languages. For this reason, there is a common mechanism for |
| 826 |
specifying these in the configuration, although no module is |
| 827 |
obligated to use it. Some synthesizers, e.g. Festival, support the |
| 828 |
SSIP symbolic names directly, so the particular configuration of these |
| 829 |
voices is done in the synthesizer itself. |
| 830 |
|
| 831 |
For each voice, there is exactly one @code{AddVoice} line. |
| 832 |
|
| 833 |
@var{language} is the ISO language code of the language of this voice, possibly |
| 834 |
with a region qualification. |
| 835 |
|
| 836 |
@var{symbolicname} is a symbolic name under which you wish this voice |
| 837 |
to be available. See @ref{Top,,Standard Voices, ssip, SSIP |
| 838 |
Documentation} for the list of names you can use. |
| 839 |
|
| 840 |
@var{name} is a name specific for the given output module. Please see |
| 841 |
the comments in the configuration file under the appropriate AddModule |
| 842 |
section for more info. |
| 843 |
|
| 844 |
For example our current definition of voices for Epos (file |
| 845 |
@code{/etc/speech-dispatcher/modules/generic-epos.conf} looks like |
| 846 |
this: |
| 847 |
|
| 848 |
@example |
| 849 |
AddVoice "cs" "male1" "kadlec" |
| 850 |
AddVoice "sk" "male1" "bob" |
| 851 |
@end example |
| 852 |
|
| 853 |
@item DefaultVoice "@var{name}" |
| 854 |
@anchor{DefaultVoice} |
| 855 |
|
| 856 |
If the client does not request for a particular voice, we should be still using |
| 857 |
some voice so that the user at least gets some feedback, even if in the wrong |
| 858 |
language. @code{DefaultVoice} can be used to specify which voice should be used |
| 859 |
in such a case. If not specified, the @code{no_voice} string is passed instead. |
| 860 |
|
| 861 |
@var{name} is a name specific for the given output module. |
| 862 |
|
| 863 |
@item GenericDelimiters "@var{delimiters}", GenericMaxChunkLength @var{length} |
| 864 |
|
| 865 |
Normally, the output module doesn't try to synthesize all |
| 866 |
incoming text at once, but instead it cuts it into smaller |
| 867 |
chunks (sentences, parts of sentences) and then synthesizes |
| 868 |
them one by one. This second approach, used by some output |
| 869 |
modules, is much faster, however it limits the ability of |
| 870 |
the output module to provide good intonation. |
| 871 |
|
| 872 |
For this reason, you can configure at which characters |
| 873 |
(@var{delimiters}) the text should be cut into smaller blocks |
| 874 |
or after how many characters (@var{length}) it should be cut, |
| 875 |
if there is no @var{delimiter} found. |
| 876 |
|
| 877 |
Making the two rules more strict, you will get better speed |
| 878 |
but give away some quality of intonation. So for example |
| 879 |
for slower computers, we recommend to include comma (,) |
| 880 |
in @var{delimiters} so that sentences are cut into phrases, |
| 881 |
while for faster computers, it's preferable |
| 882 |
not to include comma and synthesize the whole compound |
| 883 |
sentence. |
| 884 |
|
| 885 |
The same applies to @code{MaxChunkLength}, it's better |
| 886 |
to set higher values for faster computers. |
| 887 |
|
| 888 |
For example, currently the default for Flite is |
| 889 |
|
| 890 |
@example |
| 891 |
FestivalMaxChunkLength 500 |
| 892 |
FestivalDelimiters ".?!;" |
| 893 |
@end example |
| 894 |
|
| 895 |
The output module may also decide to cut sentences on delimiters |
| 896 |
only if they are followed by a space. This way for example |
| 897 |
``file123.tmp'' would not be cut in two parts, but ``The horse |
| 898 |
raced around the fence, that was lately painted green, fell.'' |
| 899 |
would be. (This is an interesting sentence, by the way.) |
| 900 |
|
| 901 |
Note: Due to |
| 902 |
@uref{https://gist.github.com/guest271314/8279ddaeeb44b9ef5f1855f6f1588d33,Bug #102 (Empty options yield to a warning)}, |
| 903 |
to remove extended silence between sentences a workaround is to |
| 904 |
include charcters that are not used in the text to speech output in the configuration, |
| 905 |
for example in a @code{~/.config/speech-dispatcher/modules/piper.conf} file |
| 906 |
|
| 907 |
@example |
| 908 |
GenericDelimiters "|" |
| 909 |
@end example |
| 910 |
@end itemize |
| 911 |
|
| 912 |
@node Configuration of the Generic Output Module, , Configuration files of output modules, Output Modules Configuration |
| 913 |
@subsubsection Configuration files of the Generic Output Module |
| 914 |
|
| 915 |
The generic output module allows you to easily write your |
| 916 |
own output module for synthesizers that have a simple |
| 917 |
command line interface by modifying the configuration |
| 918 |
file. This way, users can add support for their device even if they don't |
| 919 |
know how to program. @xref{AddModule}. |
| 920 |
|
| 921 |
The core part of a generic output module is the command |
| 922 |
execution line. |
| 923 |
|
| 924 |
@defvr {Generic Module Configuration} GenericExecuteSynth "@var{execution_string}" |
| 925 |
|
| 926 |
@code{execution_string} is the command that should be executed |
| 927 |
in a shell when it's desired to say something. In fact, it can |
| 928 |
be multiple commands concatenated by the @code{&&} operator. To stop |
| 929 |
saying the message, the output module will send a KILL signal to |
| 930 |
the process group, so it's important that it immediately |
| 931 |
stops speaking after the processes are killed. (On most GNU/Linux |
| 932 |
system, the @code{play} utility has this property). |
| 933 |
|
| 934 |
In the execution string, you can use the following variables, |
| 935 |
which will be substituted by the desired values before executing |
| 936 |
the command. |
| 937 |
|
| 938 |
@itemize |
| 939 |
@item @code{$DATA} |
| 940 |
The text data that should be said. The string's characters that would interfere |
| 941 |
with bash processing are already escaped. However, it may be necessary to put |
| 942 |
double quotes around it (like this: @code{\"$DATA\"}). |
| 943 |
@item @code{$LANGUAGE} |
| 944 |
The language identification string (it's defined by GenericLanguage). |
| 945 |
@item @code{$VOICE} |
| 946 |
The voice identification string (it's defined by AddVoice). |
| 947 |
@item @code{$PITCH} |
| 948 |
The desired pitch (a float number defined in GenericPitchAdd and GenericPitchMultiply). |
| 949 |
@item @code{$PITCH_RANGE} |
| 950 |
The desired pitch range (a float number defined in GenericPitchRangeAdd and GenericPitchRangeMultiply). |
| 951 |
@item @code{$RATE} |
| 952 |
The desired rate or speed (a float number defined in GenericRateAdd and GenericRateMultiply) |
| 953 |
@end itemize |
| 954 |
|
| 955 |
Here is an example from @file{etc/speech-dispatcher/modules/epos-generic.conf} |
| 956 |
@example |
| 957 |
GenericExecuteSynth \ |
| 958 |
"epos-say -o --language $LANGUAGE --voice $VOICE --init_f $PITCH --init_t $RATE \ |
| 959 |
\"$DATA\" | sed -e s+unknown.*$++ >/tmp/epos-said.wav && play /tmp/epos-said.wav >/dev/null" |
| 960 |
@end example |
| 961 |
@end defvr |
| 962 |
|
| 963 |
@defvr {GenericModuleConfiguration} AddVoice "@var{language}" "@var{symbolicname}" "@var{name}" |
| 964 |
@xref{AddVoice}. |
| 965 |
@end defvr |
| 966 |
|
| 967 |
@defvr {GenericModuleConfiguration} GenericDefaultCharset "character-set" |
| 968 |
|
| 969 |
Defines the default character set in which the text will be passed to the |
| 970 |
module. If unset, it defaults to @code{iso-8859-1}. |
| 971 |
|
| 972 |
@example |
| 973 |
GenericDefaultCharset "iso-8859-2" |
| 974 |
@end example |
| 975 |
@end defvr |
| 976 |
|
| 977 |
@defvr {GenericModuleConfiguration} GenericLanguage "iso-code" "string-subst" "character-set" |
| 978 |
|
| 979 |
Defines which string @code{string-subst} should be substituted for @code{$LANGUAGE} |
| 980 |
given an @code{iso-code} language code. Optionally, the character set in which |
| 981 |
the text will be passed to the module can be specified. If unset, it will |
| 982 |
default to the @code{GenericDefaultCharset} parameter. |
| 983 |
|
| 984 |
Another example from Epos generic: |
| 985 |
@example |
| 986 |
GenericLanguage "en-US" "english-US" |
| 987 |
GenericLanguage "cs" "czech" "iso-8859-2" |
| 988 |
GenericLanguage "sk" "slovak" "iso-8859-2" |
| 989 |
@end example |
| 990 |
@end defvr |
| 991 |
|
| 992 |
@defvr {GenericModuleConfiguration} GenericRateAdd @var{num} |
| 993 |
@end defvr |
| 994 |
@defvr {GenericModuleConfiguration} GenericRateMultiply @var{num} |
| 995 |
@end defvr |
| 996 |
@defvr {GenericModuleConfiguration} GenericPitchAdd @var{num} |
| 997 |
@end defvr |
| 998 |
@defvr {GenericModuleConfiguration} GenericPitchMultiply @var{num} |
| 999 |
@end defvr |
| 1000 |
@defvr {GenericModuleConfiguration} GenericPitchRangeAdd @var{num} |
| 1001 |
@end defvr |
| 1002 |
@defvr {GenericModuleConfiguration} GenericPitchRangeMultiply @var{num} |
| 1003 |
These parameters set rate and pitch conversion to compute |
| 1004 |
the value of @code{$RATE}, @code{$PITCH} and @code{$PITCH_RANGE}. |
| 1005 |
|
| 1006 |
The resulting rate (or pitch) is calculated using the following formula: |
| 1007 |
@example |
| 1008 |
(speechd_rate * GenericRateMultiply) + GenericRateAdd |
| 1009 |
@end example |
| 1010 |
where speechd_rate is a value between -100 (lowest) and +100 (highest) |
| 1011 |
Some meaningful conversion for the specific text-to-speech system |
| 1012 |
used must by defined. |
| 1013 |
|
| 1014 |
(The values in GenericSthMultiply are multiplied by 100 because |
| 1015 |
DotConf currently doesn't support floats. So you can write 0.85 as 85 and |
| 1016 |
so on.) |
| 1017 |
@end defvr |
| 1018 |
|
| 1019 |
@node Log Levels, , Output Modules Configuration, Configuration |
| 1020 |
@subsection Log Levels |
| 1021 |
|
| 1022 |
There are 6 different verbosity levels of Speech Dispatcher logging. |
| 1023 |
0 means no logging, while 5 means that nearly all the information |
| 1024 |
about Speech Dispatcher's operation is logged. |
| 1025 |
|
| 1026 |
@itemize @bullet |
| 1027 |
|
| 1028 |
@item Level 0 |
| 1029 |
@itemize @bullet |
| 1030 |
@item No information. |
| 1031 |
@end itemize |
| 1032 |
|
| 1033 |
@item Level 1 |
| 1034 |
@itemize @bullet |
| 1035 |
@item Information about loading and exiting. |
| 1036 |
@end itemize |
| 1037 |
|
| 1038 |
@item Level 2 |
| 1039 |
@itemize @bullet |
| 1040 |
@item Information about errors that occurred. |
| 1041 |
@item Allocating and freeing resources on start and exit. |
| 1042 |
@end itemize |
| 1043 |
|
| 1044 |
@item Level 3 |
| 1045 |
@itemize @bullet |
| 1046 |
@item Information about accepting/rejecting/closing clients' connections. |
| 1047 |
@item Information about invalid client commands. |
| 1048 |
@end itemize |
| 1049 |
|
| 1050 |
@item Level 4 |
| 1051 |
@itemize @bullet |
| 1052 |
@item Every received command is output. |
| 1053 |
@item Information preceding the command output. |
| 1054 |
@item Information about queueing/allocating messages. |
| 1055 |
@item Information about the history, sound icons and other |
| 1056 |
facilities. |
| 1057 |
@item Information about the work of the speak() thread. |
| 1058 |
@end itemize |
| 1059 |
|
| 1060 |
@item Level 5 |
| 1061 |
(This is only for debugging purposes and will output *a lot* |
| 1062 |
of data. Use with caution.) |
| 1063 |
@itemize @bullet |
| 1064 |
@item Received data (messages etc.) is output. |
| 1065 |
@item Debugging information. |
| 1066 |
@end itemize |
| 1067 |
@end itemize |
| 1068 |
|
| 1069 |
@node Tools, Synthesis Output Modules, Configuration, User's Documentation |
| 1070 |
@section Tools |
| 1071 |
|
| 1072 |
Several small tools are distributed together with Speech Dispatcher. |
| 1073 |
@code{spd-say} is a small client that allows you to send messages to |
| 1074 |
Speech Dispatcher in an easy way and have them spoken, or cancel |
| 1075 |
speech from other applications. |
| 1076 |
|
| 1077 |
@menu |
| 1078 |
* spd-say:: Say a given text or cancel messages in Dispatcher. |
| 1079 |
* spd-conf:: Configuration, diagnostics and troubleshooting tool |
| 1080 |
* spd-send:: Direct SSIP communication from command line. |
| 1081 |
@end menu |
| 1082 |
|
| 1083 |
@node spd-say, spd-conf, Tools, Tools |
| 1084 |
@subsection spd-say |
| 1085 |
|
| 1086 |
spd-say is documented in its own manual. @xref{Top,,,spd-say, Spd-say |
| 1087 |
Documentation}. |
| 1088 |
|
| 1089 |
@node spd-conf, spd-send, spd-say, Tools |
| 1090 |
@subsection spd-conf |
| 1091 |
|
| 1092 |
spd-conf is a tool for creating basic configuration, initial setup of |
| 1093 |
some basic settings (output module, audio method), diagnostics and |
| 1094 |
automated debugging with a possibility to send the debugging output to |
| 1095 |
the developers with a request for help. |
| 1096 |
|
| 1097 |
The available command options are self-documented through |
| 1098 |
@code{spd-say -h}. In any working mode, the tool asks the user about |
| 1099 |
future actions and preferred configuration of the basic options. |
| 1100 |
|
| 1101 |
Most useful ways of execution are: |
| 1102 |
@itemize @bullet |
| 1103 |
@item @code{spd-conf} |
| 1104 |
Create new configuration and setup basic settings according to user |
| 1105 |
answers. Run diagnostics and if some problems occur, run debugging |
| 1106 |
and offer to send a request for help to the developers. |
| 1107 |
|
| 1108 |
@item @code{spd-conf -d} |
| 1109 |
Run diagnostics of problems. |
| 1110 |
|
| 1111 |
@item @code{spd-conf -D} |
| 1112 |
Run debugging and offer to send a request for help to the developers. |
| 1113 |
|
| 1114 |
@end itemize |
| 1115 |
|
| 1116 |
@node spd-send, , spd-conf, Tools |
| 1117 |
@subsection spd-send |
| 1118 |
|
| 1119 |
spd-send is a small client/server application that allows you to |
| 1120 |
establish a connection to Speech Dispatcher and then use a simple |
| 1121 |
command line tool to send and receive SSIP protocol communication. |
| 1122 |
|
| 1123 |
Please see @file{src/c/clients/spd-say/README} in the Speech |
| 1124 |
Dispatcher's source tree for more information. |
| 1125 |
|
| 1126 |
@node Synthesis Output Modules, Security, Tools, User's Documentation |
| 1127 |
@section Synthesis Output Modules |
| 1128 |
@cindex output module |
| 1129 |
@cindex different synthesizers |
| 1130 |
|
| 1131 |
Speech Dispatcher supports concurrent use of multiple output modules. If the |
| 1132 |
output modules provide good synchronization, you can combine them when |
| 1133 |
reading messages. For example if module1 can speak English and Czech while |
| 1134 |
module2 speaks only German, the idea is that if there is some message in |
| 1135 |
German, module2 is used, while module1 is used for the other languages. |
| 1136 |
However the language is not the only criteria for the decision. |
| 1137 |
|
| 1138 |
The set of modules can be set in @file{speech-dispatcher/speechd.conf}, or left |
| 1139 |
to be determined automatically. It can be refreshed by making Speech Dispatcher |
| 1140 |
reload the configuration, with e.g. |
| 1141 |
|
| 1142 |
@example |
| 1143 |
killall -HUP speech-dispatcher |
| 1144 |
@end example |
| 1145 |
|
| 1146 |
The rules for selection of an output module can be influenced through the |
| 1147 |
configuration file @file{speech-dispatcher/speechd.conf}. |
| 1148 |
|
| 1149 |
@menu |
| 1150 |
* Provided Functionality:: Some synthesizers don't support the full set of SSIP features. |
| 1151 |
@end menu |
| 1152 |
|
| 1153 |
@node Provided Functionality, , Synthesis Output Modules, Synthesis Output Modules |
| 1154 |
@subsection Provided functionality |
| 1155 |
|
| 1156 |
Please note that some output modules don't support the full Speech |
| 1157 |
Dispatcher functionality (e.g. spelling mode, sound icons). If there |
| 1158 |
is no easy way around the missing functionality, we don't try to |
| 1159 |
emulate it in some complicated way and rather try to encourage the |
| 1160 |
developers of that particular synthesizer to add that |
| 1161 |
functionality. We are actively working on adding the missing parts to |
| 1162 |
Festival, so Festival supports nearly all of the features of Speech |
| 1163 |
Dispatcher and we encourage you to use it. Much progress has also been |
| 1164 |
done with eSpeak. |
| 1165 |
|
| 1166 |
@menu |
| 1167 |
* Supported Modules:: |
| 1168 |
@end menu |
| 1169 |
|
| 1170 |
@node Supported Modules, , Provided Functionality, Provided Functionality |
| 1171 |
@subsubsection Supported Modules |
| 1172 |
|
| 1173 |
@itemize @bullet |
| 1174 |
|
| 1175 |
@item Festival |
| 1176 |
Festival is a free software multi-language Text-to-Speech |
| 1177 |
synthesis system that is very flexible and extensible using the |
| 1178 |
Scheme scripting language. Currently, it supports high quality |
| 1179 |
synthesis for several languages, and on today's computers it runs |
| 1180 |
reasonably fast. If you are not sure which one to use and your |
| 1181 |
language is supported by Festival, we advise you to use it. See |
| 1182 |
@uref{http://www.cstr.ed.ac.uk/projects/festival/}. |
| 1183 |
|
| 1184 |
@item eSpeak |
| 1185 |
eSpeak is a newer very lightweight free software engine with a broad |
| 1186 |
range of supported languages and a good quality of voice at high |
| 1187 |
rates. See @uref{http://espeak.sourceforge.net/}. |
| 1188 |
|
| 1189 |
@item Flite |
| 1190 |
Flite (Festival Light) is a lightweight free software TTS synthesizer |
| 1191 |
intended to run on systems with limited resources. At this time, it |
| 1192 |
has only one English voice and porting voices from Festival looks |
| 1193 |
rather difficult. With the caching mechanism provided by Speech |
| 1194 |
Dispatcher, Festival is faster than Flite in most situations. See |
| 1195 |
@uref{http://www.speech.cs.cmu.edu/flite/}. |
| 1196 |
|
| 1197 |
@item Generic |
| 1198 |
The Generic module can be used with any synthesizer that can be |
| 1199 |
managed by a simple command line application. @xref{Configuration of |
| 1200 |
the Generic Output Module}, for more details about how to use it. |
| 1201 |
However, it provides only very rudimentary support of speaking. |
| 1202 |
|
| 1203 |
@item Pico |
| 1204 |
The SVOX Pico engine is a software speech synthesizer for German, English (GB |
| 1205 |
and US), Spanish, French and Italian. |
| 1206 |
SVOX produces clear and distinct speech output made possible by the use of |
| 1207 |
Hidden Markov Model (HMM) algorithms. |
| 1208 |
See @uref{http://git.debian.org/?p=collab-maint/svox.git}. |
| 1209 |
Pico documentation can be found at |
| 1210 |
@uref{http://android.git.kernel.org/?p=platform/external/svox.git; |
| 1211 |
a=tree;f=pico_resources/docs} |
| 1212 |
It includes three manuals: |
| 1213 |
- SVOX_Pico_Lingware.pdf |
| 1214 |
- SVOX_Pico_Manual.pdf |
| 1215 |
- SVOX_Pico_architecture_and_design.pdf |
| 1216 |
|
| 1217 |
@end itemize |
| 1218 |
|
| 1219 |
@node Security, , Synthesis Output Modules, User's Documentation |
| 1220 |
@section Security |
| 1221 |
|
| 1222 |
Speech Dispatcher doesn't implement any special authentication |
| 1223 |
mechanisms but uses the standard system mechanisms to regulate access. |
| 1224 |
|
| 1225 |
If the default `unix_socket' communication mechanism is used, only the |
| 1226 |
user who starts the server can connect to it due to imposed |
| 1227 |
restrictions on the unix socket file permissions. |
| 1228 |
|
| 1229 |
In case of the `inet_socket' communication mechanism, where clients |
| 1230 |
connect to Speech Dispatcher on a specified port, theoretically |
| 1231 |
everyone could connect to it. The access is by default restricted only |
| 1232 |
for connections originating on the same machine, which can be changed |
| 1233 |
via the LocalhostAccessOnly option in the server configuration |
| 1234 |
file. In such a case, the user is responsible to set appropriate |
| 1235 |
security restrictions on the access to the given port on his machine |
| 1236 |
from the outside network using a firewall or similar mechanism. |
| 1237 |
|
| 1238 |
@node Technical Specifications, Client Programming, User's Documentation, Top |
| 1239 |
@chapter Technical Specifications |
| 1240 |
|
| 1241 |
|
| 1242 |
@menu |
| 1243 |
* Communication mechanisms:: |
| 1244 |
* Address specification:: |
| 1245 |
* Actions performed on startup:: |
| 1246 |
* Accepted signals:: |
| 1247 |
@end menu |
| 1248 |
|
| 1249 |
@node Communication mechanisms, Address specification, Technical Specifications, Technical Specifications |
| 1250 |
@section Communication mechanisms |
| 1251 |
|
| 1252 |
Speech Dispatcher supports two communication mechanisms: UNIX-style |
| 1253 |
and Inet sockets, which are referred as 'unix-socket' and 'inet-socket' |
| 1254 |
respectively. The communication mechanism is decided on startup and |
| 1255 |
cannot be changed at runtime. Unix sockets are now the default and |
| 1256 |
preferred variant for local communication, Inet sockets are necessary |
| 1257 |
for communication over network. |
| 1258 |
|
| 1259 |
The mechanism for the decision of which method to use is as follows in |
| 1260 |
this order of precedence: command-line option, configuration option, |
| 1261 |
the default value 'unix-socket'. |
| 1262 |
|
| 1263 |
@emph{Unix sockets} are associated with a file in the filesystem. By |
| 1264 |
default, this file is placed in the user's runtime directory (as |
| 1265 |
determined by the value of the XDG_RUNTIME_DIR environment variable and the |
| 1266 |
system configuration for the given user). It's default name is |
| 1267 |
constructed as @code{XDG_RUNTIME_DIR/speech-dispatcher/speechd.sock}. The access |
| 1268 |
permissions for this file are set to 600 so that it's restricted to |
| 1269 |
read/write by the current user. |
| 1270 |
|
| 1271 |
As such, access is handled properly and there are no conflicts between |
| 1272 |
the different instances of Speech Dispatcher run by the different |
| 1273 |
users. |
| 1274 |
|
| 1275 |
Client applications and libraries are supposed to independently |
| 1276 |
replicate the process of construction of the socket path and connect |
| 1277 |
to it, thus establishing a common communication channel in the default |
| 1278 |
setup. |
| 1279 |
|
| 1280 |
It should be however possible in the client libraries and is possible |
| 1281 |
in the server, to define a custom file as a socket name if needed. |
| 1282 |
Client libraries should respect the @var{SPEECHD_ADDRESS} environment |
| 1283 |
variable. |
| 1284 |
|
| 1285 |
@emph{Inet sockets} are based on communication over a given port on |
| 1286 |
the given host, two variables which must be previously agreed between |
| 1287 |
the server and client before a connection can be established. The only |
| 1288 |
implicit security restriction is the server configuration option which |
| 1289 |
can allow or disallow access from machines other than localhost. |
| 1290 |
|
| 1291 |
By convention, the clients should use host and port given by one of |
| 1292 |
the following sources in the following order of precedence: its own |
| 1293 |
configuration, value of the @var{SPEECHD_ADDRESS} environment variable |
| 1294 |
and the default pair (localhost, 6560). |
| 1295 |
|
| 1296 |
@xref{Setting Communication Method}. |
| 1297 |
|
| 1298 |
@node Address specification, Actions performed on startup, Communication mechanisms, Technical Specifications |
| 1299 |
@section Address specification |
| 1300 |
|
| 1301 |
Speech Dispatcher provides several methods of communication and can be |
| 1302 |
used both locally and over network. @xref{Communication |
| 1303 |
mechanisms}. Client applications and interface libraries need to |
| 1304 |
recognize an address, which specifies how and where to contact the |
| 1305 |
appropriate server. |
| 1306 |
|
| 1307 |
Address specification consists from the method and one or more of its |
| 1308 |
parameters, each item separated by a colon: |
| 1309 |
|
| 1310 |
@example |
| 1311 |
method:parameter1:parameter2 |
| 1312 |
@end example |
| 1313 |
|
| 1314 |
The method is either 'unix_socket' or 'inet_socket'. Parameters are |
| 1315 |
optional. If not used in the address line, their default value will |
| 1316 |
be used. |
| 1317 |
|
| 1318 |
Two forms are currently recognized: |
| 1319 |
|
| 1320 |
@example |
| 1321 |
unix_socket:full/path/to/socket |
| 1322 |
inet_socket:host_ip:port |
| 1323 |
@end example |
| 1324 |
|
| 1325 |
Examples of valid address lines are: |
| 1326 |
@example |
| 1327 |
unix_socket |
| 1328 |
unix_socket:/tmp/test.sock |
| 1329 |
inet_socket |
| 1330 |
inet_socket:192.168.0.34 |
| 1331 |
inet_socket:192.168.0.34:6563 |
| 1332 |
@end example |
| 1333 |
|
| 1334 |
Clients implement different mechanisms how the user can set the |
| 1335 |
address. Clients should respect the @var{SPEECHD_ADDRESS} environment |
| 1336 |
variable @xref{Setting Communication Method}, unless the user |
| 1337 |
overrides its value by settings in the client application |
| 1338 |
itself. Clients should fallback to the default address, if neither the |
| 1339 |
environment variable or their specific configuration is set. |
| 1340 |
|
| 1341 |
The default communication address currently is: |
| 1342 |
|
| 1343 |
@example |
| 1344 |
unix_socket:/$XDG_RUNTIME_DIR/speech-dispatcher/speechd.sock |
| 1345 |
@end example |
| 1346 |
|
| 1347 |
where `~' stands for the path to the users home directory. |
| 1348 |
|
| 1349 |
@node Actions performed on startup, Accepted signals, Address specification, Technical Specifications |
| 1350 |
@section Actions performed on startup |
| 1351 |
|
| 1352 |
What follows is an overview of the actions the server takes on startup |
| 1353 |
in this order: |
| 1354 |
|
| 1355 |
@itemize @bullet |
| 1356 |
|
| 1357 |
@item Initialize logging stage 1 |
| 1358 |
|
| 1359 |
Set loglevel to 1 and log destination to stderr (logfile is not ready yet). |
| 1360 |
|
| 1361 |
@item Parse command line options |
| 1362 |
|
| 1363 |
Read preferred communication method, destinations for logfile and pidfile |
| 1364 |
|
| 1365 |
@item Establish the @file{~/.config/speech-dispatcher/} and |
| 1366 |
@file{~/.cache/speech-dispatcher/} directories |
| 1367 |
|
| 1368 |
If pid and conf paths were not given as command line options, the |
| 1369 |
server will place them in @file{~/.config/speech-dispatcher/} and |
| 1370 |
@file{~/.cache/speech-dispatcher/} by default. If they |
| 1371 |
are not specified AND the current user doesn't have a system home directory, |
| 1372 |
the server will fail startup. |
| 1373 |
|
| 1374 |
The configuration file is pointed to @file{~/.config/speech-dispatcher/speechd.conf} |
| 1375 |
if it exists, otherwise to @file{/etc/speech-dispatcher/speechd.conf} or a similar |
| 1376 |
system location according to compile options. One of these files must |
| 1377 |
exists, otherwise Speech Dispatcher will not know where to find its output |
| 1378 |
modules. |
| 1379 |
|
| 1380 |
@item Create pid file |
| 1381 |
|
| 1382 |
Check the pid file in the determined location. If an instance of the |
| 1383 |
server is already running, log an error message and exit with error |
| 1384 |
code 1, otherwise create and lock a new pid file. |
| 1385 |
|
| 1386 |
@item Check for autospawning enabled |
| 1387 |
|
| 1388 |
If the server is started with --spawn, check whether autospawn is not |
| 1389 |
disabled in the configuration (DisableAutoSpawn config option in |
| 1390 |
speechd.conf). If it is disabled, log an error message and exit with |
| 1391 |
error code 1. |
| 1392 |
|
| 1393 |
@item Install signal handlers |
| 1394 |
|
| 1395 |
@item Create unix or inet sockets and start listening |
| 1396 |
|
| 1397 |
@item Initialize Speech Dispatcher |
| 1398 |
|
| 1399 |
Read the configuration files, setup some lateral threads, start and |
| 1400 |
initialize output modules. Reinitialize logging (stage 2) into the |
| 1401 |
final logfile destination (as determined by the command line option, |
| 1402 |
the configuration option and the default location in this order of |
| 1403 |
precedence). |
| 1404 |
|
| 1405 |
After this step, Speech Dispatcher is ready to accept new connections. |
| 1406 |
|
| 1407 |
@item Daemonize the process |
| 1408 |
|
| 1409 |
Fork the process, disconnect from standard input and outputs, |
| 1410 |
disconnect from parent process etc. as prescribed by the POSIX |
| 1411 |
standards. |
| 1412 |
|
| 1413 |
@item Initialize the speaking lateral thread |
| 1414 |
|
| 1415 |
Initialize the second main thread which will process the speech |
| 1416 |
request from the queues and pass them onto the Speech Dispatcher |
| 1417 |
modules. |
| 1418 |
|
| 1419 |
|
| 1420 |
@item Start accepting new connections from clients |
| 1421 |
|
| 1422 |
Start listening for new connections from clients and processing them |
| 1423 |
in a loop. |
| 1424 |
|
| 1425 |
@end itemize |
| 1426 |
|
| 1427 |
@node Accepted signals, , Actions performed on startup, Technical Specifications |
| 1428 |
@section Accepted signals |
| 1429 |
|
| 1430 |
@itemize @bullet |
| 1431 |
|
| 1432 |
@item SIGINT |
| 1433 |
|
| 1434 |
Terminate the server |
| 1435 |
|
| 1436 |
@item SIGHUP |
| 1437 |
|
| 1438 |
Reload configuration from config files but do not restart modules |
| 1439 |
|
| 1440 |
@item SIGUSR1 |
| 1441 |
|
| 1442 |
Reload dead output modules (modules which were previously working but |
| 1443 |
crashed during runtime and marked as dead) |
| 1444 |
|
| 1445 |
@item SIGPIPE |
| 1446 |
|
| 1447 |
Ignored |
| 1448 |
|
| 1449 |
@end itemize |
| 1450 |
|
| 1451 |
@node Client Programming, Server Programming, Technical Specifications, Top |
| 1452 |
@chapter Client Programming |
| 1453 |
|
| 1454 |
Clients communicate with Speech Dispatcher via the Speech Synthesis |
| 1455 |
Internet Protocol (SSIP) @xref{Top, , , ssip, Speech Synthesis |
| 1456 |
Internet Protocol documentation}. The protocol is the actual |
| 1457 |
interface to Speech Dispatcher. |
| 1458 |
|
| 1459 |
Usually you don't need to use SSIP directly. You can use one of the supplied |
| 1460 |
libraries, which wrap the SSIP interface. This is the |
| 1461 |
recommended way of communicating with Speech Dispatcher. We try so support as |
| 1462 |
many programming environments as possible. This manual (except SSIP) contains |
| 1463 |
documentation for the C and Python libraries, however there are also other |
| 1464 |
libraries developed as external projects. Please contact us for information |
| 1465 |
about current external client libraries. |
| 1466 |
|
| 1467 |
@menu |
| 1468 |
* C API:: Shared library for C/C++ |
| 1469 |
* Python API:: Python module. |
| 1470 |
* Guile API:: |
| 1471 |
* Common Lisp API:: |
| 1472 |
* Golang API:: |
| 1473 |
* Autospawning:: How server is started from clients |
| 1474 |
@end menu |
| 1475 |
|
| 1476 |
@node C API, Python API, Client Programming, Client Programming |
| 1477 |
@section C API |
| 1478 |
|
| 1479 |
@menu |
| 1480 |
* Initializing and Terminating in C:: |
| 1481 |
* Speech Synthesis Commands in C:: |
| 1482 |
* Speech output control commands in C:: |
| 1483 |
* Characters and Keys in C:: |
| 1484 |
* Sound Icons in C:: |
| 1485 |
* Parameter Setting Commands in C:: |
| 1486 |
* Other Functions in C:: |
| 1487 |
* Information Retrieval Commands in C:: |
| 1488 |
* Event Notification and Index Marking in C:: |
| 1489 |
* History Commands in C:: |
| 1490 |
* Direct SSIP Communication in C:: |
| 1491 |
@end menu |
| 1492 |
|
| 1493 |
@node Initializing and Terminating in C, Speech Synthesis Commands in C, C API, C API |
| 1494 |
@subsection Initializing and Terminating |
| 1495 |
|
| 1496 |
@deffn {C API function} SPDConnection* spd_open(const char* client_name, const char* connection_name, const char* user_name, SPDConnectionMode connection_mode) |
| 1497 |
@findex spd_open() |
| 1498 |
|
| 1499 |
Opens a new connection to Speech Dispatcher and returns a socket file |
| 1500 |
descriptor you will use to communicate with Speech Dispatcher. The |
| 1501 |
socket file descriptor is a parameter used in all the other |
| 1502 |
functions. It now uses local communication via inet sockets. |
| 1503 |
See @code{spd_open2} for more details. |
| 1504 |
|
| 1505 |
The three parameters @code{client_name}, @code{connection_name} and |
| 1506 |
@code{username} are there only for informational and navigational |
| 1507 |
purposes, they don't affect any settings or behavior of any |
| 1508 |
functions. The authentication mechanism has nothing to do with |
| 1509 |
@code{username}. These parameters are important for the user when he |
| 1510 |
wants to set some parameters for a given session, when he wants to |
| 1511 |
browse through history, etc. The parameter @code{connection_mode} |
| 1512 |
specifies how this connection should be handled internally and if |
| 1513 |
event notifications and index marking capabilities will be available. |
| 1514 |
|
| 1515 |
@code{client_name} is the name of the client that opens the connection. Normally, |
| 1516 |
it should be the name of the executable, for example ``lynx'', ``emacs'', ``bash'', |
| 1517 |
or ``gcc''. It can be left as NULL. |
| 1518 |
|
| 1519 |
@code{connection_name} determines the particular use of that connection. If you |
| 1520 |
use only one connection in your program, this should be set to ``main'' (passing |
| 1521 |
a NULL pointer has the same effect). If you use two or more connections in |
| 1522 |
your program, their @code{client_name}s should be the same, but @code{connection_name}s |
| 1523 |
should differ. For example: ``buffer'', ``command_line'', ``text'', ``menu''. |
| 1524 |
|
| 1525 |
@code{username} should be set to the name of the user. Normally, you should |
| 1526 |
get this string from the system. If set to NULL, libspeechd will try to |
| 1527 |
determine it automatically by g_get_user_name(). |
| 1528 |
|
| 1529 |
@code{connection_mode} has two possible values: @code{SPD_MODE_SINGLE} |
| 1530 |
and @code{SPD_MODE_THREADED}. If the parameter is set to |
| 1531 |
@code{SPD_MODE_THREADED}, then @code{spd_open()} will open an |
| 1532 |
additional thread in your program which will handle asynchronous SSIP |
| 1533 |
replies and will allow you to use callbacks for event notifications |
| 1534 |
and index marking, allowing you to keep track of the progress |
| 1535 |
of speaking the messages. However, you must be aware that your |
| 1536 |
program is now multi-threaded and care must be taken when |
| 1537 |
using/handling signals. If @code{SPD_MODE_SINGLE} is chosen, the |
| 1538 |
library won't execute any additional threads and SSIP will run only as |
| 1539 |
a synchronous protocol, therefore event notifications and index |
| 1540 |
marking won't be available. |
| 1541 |
|
| 1542 |
It returns a newly allocated SPDConnection* structure on success, or @code{NULL} |
| 1543 |
on error. |
| 1544 |
|
| 1545 |
Each connection you open should be closed by spd_close() before the |
| 1546 |
end of the program, so that the associated connection descriptor is |
| 1547 |
closed, threads are terminated and memory is freed. |
| 1548 |
|
| 1549 |
@end deffn |
| 1550 |
|
| 1551 |
@deffn {C API function} SPDConnection* spd_open2(const char* client_name, const char* connection_name, const char* user_name, SPDConnectionMode connection_mode, const SPDConnectionAddress * address, int autospawn, char **error_result) |
| 1552 |
@findex spd_open2() |
| 1553 |
|
| 1554 |
Opens a new connection to Speech Dispatcher and returns a socket file |
| 1555 |
descriptor. This function is the same as @code{spd_open} except that |
| 1556 |
it gives more control of the communication method and autospawn |
| 1557 |
functionality as described below. |
| 1558 |
|
| 1559 |
@code{address} designates the address to which this should connect to. |
| 1560 |
Setting this to NULL lets libspeechd use the default address (as reported by |
| 1561 |
@code{spd_get_default_address}). |
| 1562 |
The @code{method} field of @code{address} can be either |
| 1563 |
@code{SPD_METHOD_UNIX_SOCKET} or @code{SPD_METHOD_INET_SOCKET}. In the Unix |
| 1564 |
case, the @code{unix_socket_name} field must be set to the Unix path. In the |
| 1565 |
Inet case, the @code{inet_socket_host} field must be set to the Inet host, and |
| 1566 |
the @code{inet_socket_port} must be set to the TCP port to be used (in host |
| 1567 |
endianness). The @code{dbus_bus} is currently unused. |
| 1568 |
|
| 1569 |
By default, unix socket communication should be preferred, but inet sockets are |
| 1570 |
necessary for cross-network communication. |
| 1571 |
|
| 1572 |
@code{autospawn} is a boolean flag specifying whether the function |
| 1573 |
should try to autospawn (autostart) the Speech Dispatcher server |
| 1574 |
process if it is not running already. This is set to 1 by default, so |
| 1575 |
this function should normally not fail even if the server is not yet |
| 1576 |
running. |
| 1577 |
|
| 1578 |
@code{error_result} has to be the address of a @code{char*} variable, which will |
| 1579 |
be filled with an error message if some error occurs. That message must be freed |
| 1580 |
with @code{free}. |
| 1581 |
|
| 1582 |
@end deffn |
| 1583 |
|
| 1584 |
@deffn {C API function} int spd_fd(SPDConnection *connection) |
| 1585 |
@findex spd_fd() |
| 1586 |
|
| 1587 |
This returns the OS-level file descriptor used for this connection. This returns |
| 1588 |
@code{-1} in case an error was detected and thus libspeechd closed the connection. |
| 1589 |
|
| 1590 |
@code{connection} is the SPDConnection connection obtained by spd_open(). |
| 1591 |
|
| 1592 |
It must be noted that in @code{SPD_MODE_THREADED} mode, the value returned by |
| 1593 |
@code{spd_fd()} can change to @code{-1} unexpectedly, since the even handler |
| 1594 |
runs concurrently in its own thread and will catch errors. The value should thus |
| 1595 |
be taken with care, as it may not actually be a valid file descriptor, or it |
| 1596 |
could even have been re-used in between. The only thing that is really sure is |
| 1597 |
that when it returns @code{-1}, the socket was closed because of an error. In |
| 1598 |
@code{SPD_MODE_SINGLE} mode, the value only changes during @code{spd_*} function |
| 1599 |
calls. |
| 1600 |
@end deffn |
| 1601 |
|
| 1602 |
@deffn {C API function} int spd_get_client_id(SPDConnection *connection) |
| 1603 |
@findex spd_get_client_id() |
| 1604 |
|
| 1605 |
Get the client ID. |
| 1606 |
|
| 1607 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1608 |
|
| 1609 |
It returns the client ID of the connection. |
| 1610 |
|
| 1611 |
@end deffn |
| 1612 |
|
| 1613 |
@deffn {C API function} void spd_close(SPDConnection *connection) |
| 1614 |
@findex spd_close() |
| 1615 |
|
| 1616 |
Closes a Speech Dispatcher socket connection, terminates associated |
| 1617 |
threads (if necessary) and frees the memory allocated by |
| 1618 |
spd_open(). You should close every connection before the end of your |
| 1619 |
program. |
| 1620 |
|
| 1621 |
@code{connection} is the SPDConnection connection obtained by spd_open(). |
| 1622 |
@end deffn |
| 1623 |
|
| 1624 |
@node Speech Synthesis Commands in C, Speech output control commands in C, Initializing and Terminating in C, C API |
| 1625 |
@subsection Speech Synthesis Commands |
| 1626 |
|
| 1627 |
@defvar {C API type} SPDPriority |
| 1628 |
@vindex SPDPriority |
| 1629 |
|
| 1630 |
@code{SPDPriority} is an enum type that represents the possible priorities that |
| 1631 |
can be assigned to a message. |
| 1632 |
|
| 1633 |
@example |
| 1634 |
typedef enum@{ |
| 1635 |
SPD_IMPORTANT = 1, |
| 1636 |
SPD_MESSAGE = 2, |
| 1637 |
SPD_TEXT = 3, |
| 1638 |
SPD_NOTIFICATION = 4, |
| 1639 |
SPD_PROGRESS = 5 |
| 1640 |
@}SPDPriority; |
| 1641 |
@end example |
| 1642 |
|
| 1643 |
@xref{Top,,Message Priority Model,ssip, SSIP Documentation}. |
| 1644 |
|
| 1645 |
@end defvar |
| 1646 |
|
| 1647 |
@deffn {C API function} int spd_say(SPDConnection* connection, SPDPriority priority, const char* text); |
| 1648 |
@findex spd_say() |
| 1649 |
|
| 1650 |
Sends a message to Speech Dispatcher. If this message isn't blocked by |
| 1651 |
some message of higher priority and this CONNECTION isn't paused, it |
| 1652 |
will be synthesized directly on one of the output devices. Otherwise, |
| 1653 |
the message will be discarded or delayed according to its priority. |
| 1654 |
|
| 1655 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1656 |
|
| 1657 |
@code{priority} is the desired priority for this message. @xref{Top,,Message Priority Model,ssip, SSIP Documentation}. |
| 1658 |
|
| 1659 |
@code{text} is a null terminated string containing text you want sent |
| 1660 |
to synthesis. It must be encoded in UTF-8. Note that this doesn't have |
| 1661 |
to be what you will finally hear. It can be affected by different |
| 1662 |
settings, such as spelling, punctuation, text substitution etc. |
| 1663 |
|
| 1664 |
It returns a positive unique message identification number on success, |
| 1665 |
-1 otherwise. This message identification number can be saved and |
| 1666 |
used for the purpose of event notification callbacks or history |
| 1667 |
handling. |
| 1668 |
|
| 1669 |
@end deffn |
| 1670 |
|
| 1671 |
@deffn {C API function} int spd_sayf(SPDConnection* connection, SPDPriority priority, const char* format, ...); |
| 1672 |
@findex spd_sayf() |
| 1673 |
|
| 1674 |
Similar to @code{spd_say()}, simulates the behavior of printf(). |
| 1675 |
|
| 1676 |
@code{format} is a string containing text and formatting of the parameters, such as ``%d'', |
| 1677 |
``%s'' etc. It must be encoded in UTF-8. |
| 1678 |
|
| 1679 |
@code{...} is an arbitrary number of arguments. |
| 1680 |
|
| 1681 |
All other parameters are the same as for spd_say(). |
| 1682 |
|
| 1683 |
For example: |
| 1684 |
@example |
| 1685 |
spd_sayf(conn, SPD_TEXT, "Hello %s, how are you?", username); |
| 1686 |
spd_sayf(conn, SPD_IMPORTANT, "Fatal error on [%s:%d]", filename, line); |
| 1687 |
@end example |
| 1688 |
|
| 1689 |
But be careful with unicode! For example this doesn't work: |
| 1690 |
|
| 1691 |
@example |
| 1692 |
spd_sayf(conn, SPD_NOTIFY, ``Pressed key is %c.'', key); |
| 1693 |
@end example |
| 1694 |
|
| 1695 |
Why? Because you are supposing that key is a char, but that will |
| 1696 |
fail with languages using multibyte charsets. The proper solution |
| 1697 |
is: |
| 1698 |
|
| 1699 |
@example |
| 1700 |
spd_sayf(conn, SPD_NOTIFY, ``Pressed key is %s'', key); |
| 1701 |
@end example |
| 1702 |
where key is an encoded string. |
| 1703 |
|
| 1704 |
It returns a positive unique message identification number on success, -1 otherwise. |
| 1705 |
This message identification number can be saved and used for the purpose of |
| 1706 |
event notification callbacks or history handling. |
| 1707 |
@end deffn |
| 1708 |
|
| 1709 |
@node Speech output control commands in C, Characters and Keys in C, Speech Synthesis Commands in C, C API |
| 1710 |
@subsection Speech Output Control Commands |
| 1711 |
|
| 1712 |
@subsubheading Stop Commands |
| 1713 |
|
| 1714 |
@deffn {C API function} int spd_stop(SPDConnection* connection); |
| 1715 |
@findex spd_stop() |
| 1716 |
|
| 1717 |
Stops the message currently being spoken on a given connection. If there |
| 1718 |
is no message being spoken, does nothing. (It doesn't touch the messages |
| 1719 |
waiting in queues). This is intended for stops executed by the user, |
| 1720 |
not for automatic stops (because automatically you can't control |
| 1721 |
how many messages are still waiting in queues on the server). |
| 1722 |
|
| 1723 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1724 |
|
| 1725 |
It returns 0 on success, -1 otherwise. |
| 1726 |
@end deffn |
| 1727 |
|
| 1728 |
@deffn {C API function} int spd_stop_all(SPDConnection* connection); |
| 1729 |
@findex spd_stop_all() |
| 1730 |
|
| 1731 |
The same as spd_stop(), but it stops every message being said, |
| 1732 |
without distinguishing where it came from. |
| 1733 |
|
| 1734 |
It returns 0 on success, -1 if some of the stops failed. |
| 1735 |
@end deffn |
| 1736 |
|
| 1737 |
@deffn {C API function} int spd_stop_uid(SPDConnection* connection, int target_uid); |
| 1738 |
@findex spd_stop_uid() |
| 1739 |
|
| 1740 |
The same as spd_stop() except that it stops a client client different from |
| 1741 |
the calling one. You must specify this client in @code{target_uid}. |
| 1742 |
|
| 1743 |
@code{target_uid} is the unique ID of the connection you want |
| 1744 |
to execute stop() on. It can be obtained from spd_history_get_client_list(). |
| 1745 |
@xref{History Commands in C}. |
| 1746 |
|
| 1747 |
It returns 0 on success, -1 otherwise. |
| 1748 |
|
| 1749 |
@end deffn |
| 1750 |
|
| 1751 |
@subsubheading Cancel Commands |
| 1752 |
|
| 1753 |
@deffn {C API function} int spd_cancel(SPDConnection* connection); |
| 1754 |
|
| 1755 |
Stops the currently spoken message from this connection |
| 1756 |
(if there is any) and discards all the queued messages |
| 1757 |
from this connection. This is probably what you want |
| 1758 |
to do, when you call spd_cancel() automatically in |
| 1759 |
your program. |
| 1760 |
@end deffn |
| 1761 |
|
| 1762 |
@deffn {C API function} int spd_cancel_all(SPDConnection* connection); |
| 1763 |
@findex spd_cancel_all() |
| 1764 |
|
| 1765 |
The same as spd_cancel(), but it cancels every message |
| 1766 |
without distinguishing where it came from. |
| 1767 |
|
| 1768 |
It returns 0 on success, -1 if some of the stops failed. |
| 1769 |
@end deffn |
| 1770 |
|
| 1771 |
@deffn {C API function} int spd_cancel_uid(SPDConnection* connection, int target_uid); |
| 1772 |
@findex spd_cancel_uid() |
| 1773 |
|
| 1774 |
The same as spd_cancel() except that it executes cancel for some other client |
| 1775 |
than the calling one. You must specify this client in @code{target_uid}. |
| 1776 |
|
| 1777 |
@code{target_uid} is the unique ID of the connection you want to |
| 1778 |
execute cancel() on. It can be obtained from |
| 1779 |
spd_history_get_client_list(). @xref{History Commands in C}. |
| 1780 |
|
| 1781 |
It returns 0 on success, -1 otherwise. |
| 1782 |
@end deffn |
| 1783 |
|
| 1784 |
@subsubheading Pause Commands |
| 1785 |
|
| 1786 |
@deffn {C API function} int spd_pause(SPDConnection* connection); |
| 1787 |
@findex int spd_pause() |
| 1788 |
|
| 1789 |
Pauses all messages received from the given connection. No messages |
| 1790 |
except for priority @code{notification} and @code{progress} are thrown |
| 1791 |
away, they are all waiting in a separate queue for resume(). Upon resume(), the |
| 1792 |
message that was being said at the moment pause() was received will be |
| 1793 |
continued from the place where it was paused. |
| 1794 |
|
| 1795 |
It returns immediately. However, that doesn't mean that the speech |
| 1796 |
output will stop immediately. Instead, it can continue speaking |
| 1797 |
the message for a while until a place where the position in the text |
| 1798 |
can be determined exactly is reached. This is necessary to be able to |
| 1799 |
provide `resume' without gaps and overlapping. |
| 1800 |
|
| 1801 |
When pause is on for the given client, all newly received |
| 1802 |
messages are also queued and waiting for resume(). |
| 1803 |
|
| 1804 |
It returns 0 on success, -1 if something failed. |
| 1805 |
@end deffn |
| 1806 |
|
| 1807 |
@deffn {C API function} int spd_pause_all(SPDConnection* connection); |
| 1808 |
@findex spd_pause_all() |
| 1809 |
|
| 1810 |
The same as spd_pause(), but it pauses every message, |
| 1811 |
without distinguishing where it came from. |
| 1812 |
|
| 1813 |
It returns 0 on success, -1 if some of the pauses failed. |
| 1814 |
@end deffn |
| 1815 |
|
| 1816 |
@deffn {C API function} int spd_pause_uid(SPDConnection* connection, int target_uid); |
| 1817 |
@findex spd_pause_uid() |
| 1818 |
|
| 1819 |
The same as spd_pause() except that it executes pause for a client different from |
| 1820 |
the calling one. You must specify the client in @code{target_uid}. |
| 1821 |
|
| 1822 |
@code{target_uid} is the unique ID of the connection you want |
| 1823 |
to pause. It can be obtained from spd_history_get_client_list(). |
| 1824 |
@xref{History Commands in C}. |
| 1825 |
|
| 1826 |
It returns 0 on success, -1 otherwise. |
| 1827 |
@end deffn |
| 1828 |
|
| 1829 |
@subsubheading Resume Commands |
| 1830 |
|
| 1831 |
@deffn {C API function} int spd_resume(SPDConnection* connection); |
| 1832 |
@findex int spd_resume() |
| 1833 |
|
| 1834 |
Resumes all paused messages from the given connection. The rest |
| 1835 |
of the message that was being said at the moment pause() was |
| 1836 |
received will be said and all the other messages are queued |
| 1837 |
for synthesis again. |
| 1838 |
|
| 1839 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1840 |
|
| 1841 |
It returns 0 on success, -1 otherwise. |
| 1842 |
@end deffn |
| 1843 |
|
| 1844 |
@deffn {C API function} int spd_resume_all(SPDConnection* connection); |
| 1845 |
@findex spd_resume_all() |
| 1846 |
|
| 1847 |
The same as spd_resume(), but it resumes every paused message, |
| 1848 |
without distinguishing where it came from. |
| 1849 |
|
| 1850 |
It returns 0 on success, -1 if some of the pauses failed. |
| 1851 |
@end deffn |
| 1852 |
|
| 1853 |
@deffn {C API function} int spd_resume_uid(SPDConnection* connection, int target_uid); |
| 1854 |
@findex spd_resume_uid() |
| 1855 |
|
| 1856 |
The same as spd_resume() except that it executes resume for a client different from |
| 1857 |
the calling one. You must specify the client in @code{target_uid}. |
| 1858 |
|
| 1859 |
@code{target_uid} is the unique ID of the connection you want |
| 1860 |
to resume. It can be obtained from spd_history_get_client_list(). |
| 1861 |
@xref{History Commands in C}. |
| 1862 |
|
| 1863 |
It returns 0 on success, -1 otherwise. |
| 1864 |
@end deffn |
| 1865 |
|
| 1866 |
@node Characters and Keys in C, Sound Icons in C, Speech output control commands in C, C API |
| 1867 |
@subsection Characters and Keys |
| 1868 |
|
| 1869 |
@deffn {C API function} int spd_char(SPDConnection* connection, SPDPriority priority, const char* character); |
| 1870 |
@findex spd_char() |
| 1871 |
|
| 1872 |
Says a character according to user settings for characters. For example, this can be |
| 1873 |
used for speaking letters under the cursor. |
| 1874 |
|
| 1875 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1876 |
|
| 1877 |
@code{priority} is the desired priority for this |
| 1878 |
message. @xref{Top,,Message Priority Model,ssip, SSIP Documentation}. |
| 1879 |
|
| 1880 |
@code{character} is a NULL terminated string of chars containing one UTF-8 |
| 1881 |
character. If it contains more characters, only the first one is processed. |
| 1882 |
|
| 1883 |
It returns 0 on success, -1 otherwise. |
| 1884 |
@end deffn |
| 1885 |
|
| 1886 |
@deffn {C API function} int spd_wchar(SPDConnection* connection, SPDPriority priority, wchar_t wcharacter); |
| 1887 |
@findex spd_say_wchar() |
| 1888 |
|
| 1889 |
The same as spd_char(), but it takes a wchar_t variable as its argument. |
| 1890 |
|
| 1891 |
It returns 0 on success, -1 otherwise. |
| 1892 |
@end deffn |
| 1893 |
|
| 1894 |
@deffn {C API function} int spd_key(SPDConnection* connection, SPDPriority priority, const char* key_name); |
| 1895 |
@findex spd_key() |
| 1896 |
|
| 1897 |
Says a key according to user settings for keys. |
| 1898 |
|
| 1899 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1900 |
|
| 1901 |
@code{priority} is the desired priority for this |
| 1902 |
message. @xref{Top,,Message Priority Model,ssip, SSIP Documentation}. |
| 1903 |
|
| 1904 |
@code{key_name} is the name of the key in a special format. |
| 1905 |
@xref{Top,,Speech Synthesis and Sound Output Commands, ssip, SSIP |
| 1906 |
Documentation}, (KEY, the corresponding SSIP command) for description |
| 1907 |
of the format of @code{key_name} |
| 1908 |
|
| 1909 |
It returns 0 on success, -1 otherwise. |
| 1910 |
@end deffn |
| 1911 |
|
| 1912 |
@node Sound Icons in C, Parameter Setting Commands in C, Characters and Keys in C, C API |
| 1913 |
@subsection Sound Icons |
| 1914 |
|
| 1915 |
@deffn {C API function} int spd_sound_icon(SPDConnection* connection, SPDPriority priority, const char* icon_name); |
| 1916 |
@findex spd_sound_icon() |
| 1917 |
|
| 1918 |
Sends a sound icon ICON_NAME. These are symbolic names that are mapped |
| 1919 |
to a sound or to a text string (in the particular language) according to |
| 1920 |
Speech Dispatcher tables and user settings. Each program can also |
| 1921 |
define its own icons. |
| 1922 |
|
| 1923 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1924 |
|
| 1925 |
@code{priority} is the desired priority for this |
| 1926 |
message. @xref{Top,,Message Priority Model,ssip, SSIP Documentation}. |
| 1927 |
|
| 1928 |
@code{icon_name} is the name of the icon. It can't contain spaces, instead |
| 1929 |
use underscores (`_'). Icon names starting with an underscore |
| 1930 |
are considered internal and shouldn't be used. |
| 1931 |
@end deffn |
| 1932 |
|
| 1933 |
@node Parameter Setting Commands in C, Other Functions in C, Sound Icons in C, C API |
| 1934 |
@subsection Parameter Settings Commands |
| 1935 |
|
| 1936 |
The following parameter setting commands are available. For configuration |
| 1937 |
and history clients there are also functions for setting the value for |
| 1938 |
some other connection and for all connections. They are listed separately below. |
| 1939 |
|
| 1940 |
Please see @ref{Top,,Parameter Setting Commands,ssip, SSIP |
| 1941 |
Documentation} for a general description of what they mean. |
| 1942 |
|
| 1943 |
@deffn {C API function} int spd_set_data_mode(SPDConnection *connection, SPDDataMode mode) |
| 1944 |
@findex spd_set_data_mode() |
| 1945 |
|
| 1946 |
Set Speech Dispatcher data mode. Currently, plain text and SSML are |
| 1947 |
supported. SSML is especially useful if you want to use index marks |
| 1948 |
or include changes of voice parameters in the text. |
| 1949 |
|
| 1950 |
@code{mode} is the requested data mode: @code{SPD_DATA_TEXT} or |
| 1951 |
@code{SPD_DATA_SSML}. |
| 1952 |
|
| 1953 |
@end deffn |
| 1954 |
|
| 1955 |
@deffn {C API function} int spd_set_language(SPDConnection* connection, const char* language); |
| 1956 |
@findex spd_set_language() |
| 1957 |
|
| 1958 |
Sets the language that should be used for synthesis. |
| 1959 |
|
| 1960 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1961 |
|
| 1962 |
@code{language} is the language code as defined in RFC 1766 (``cs'', |
| 1963 |
``en'', ``en-US'', ...). |
| 1964 |
|
| 1965 |
@end deffn |
| 1966 |
|
| 1967 |
@deffn {C API function} int spd_set_output_module(SPDConnection* connection, const char* output_module); |
| 1968 |
@findex spd_set_output_module() |
| 1969 |
@anchor{spd_set_output_module} |
| 1970 |
|
| 1971 |
Sets the output module that should be used for synthesis. The parameter |
| 1972 |
of this command should always be entered by the user in some way |
| 1973 |
and not hardcoded anywhere in the code as the available synthesizers |
| 1974 |
and their registration names may vary from machine to machine. |
| 1975 |
|
| 1976 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1977 |
|
| 1978 |
@code{output_module} is the output module name under which the module |
| 1979 |
was loaded into Speech Dispatcher in its configuration (``flite'', |
| 1980 |
``festival'', ``epos-generic''... ) |
| 1981 |
|
| 1982 |
@end deffn |
| 1983 |
|
| 1984 |
@deffn {C API function} char* spd_get_output_module(SPDConnection* connection); |
| 1985 |
@findex spd_get_output_module() |
| 1986 |
@anchor{spd_get_output_module} |
| 1987 |
|
| 1988 |
Gets the current output module in use for synthesis. |
| 1989 |
|
| 1990 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 1991 |
|
| 1992 |
It returns the output module name under which the module was loaded into Speech |
| 1993 |
Dispatcher in its configuration (``flite'', ``festival'', ``espeak''... ) |
| 1994 |
|
| 1995 |
The caller has to @code{free} the returned string. |
| 1996 |
|
| 1997 |
@end deffn |
| 1998 |
|
| 1999 |
@deffn {C API function} char* spd_get_language(SPDConnection* connection); |
| 2000 |
@findex spd_get_language() |
| 2001 |
@anchor{spd_get_language} |
| 2002 |
|
| 2003 |
Gets the current language in use for synthesis. |
| 2004 |
|
| 2005 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2006 |
|
| 2007 |
It returns the name of the currently used language (``en-US'', ``fr-FR'', ...) |
| 2008 |
|
| 2009 |
The caller has to @code{free} the returned string. |
| 2010 |
|
| 2011 |
@end deffn |
| 2012 |
|
| 2013 |
@deffn {C API function} int spd_set_punctuation(SPDConnection* connection, SPDPunctuation type); |
| 2014 |
@findex spd_set_punctuation() |
| 2015 |
|
| 2016 |
Set punctuation mode to the given value. `all' means speak all |
| 2017 |
punctuation characters, `none' means speak no punctuation characters, |
| 2018 |
`some' and `most' mean speak intermediate sets of punctuation characters as |
| 2019 |
set in symbols tables or output modules. |
| 2020 |
|
| 2021 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2022 |
|
| 2023 |
@code{type} is one of the following values: @code{SPD_PUNCT_ALL}, |
| 2024 |
@code{SPD_PUNCT_NONE}, @code{SPD_PUNCT_SOME}. |
| 2025 |
|
| 2026 |
It returns 0 on success, -1 otherwise. |
| 2027 |
@end deffn |
| 2028 |
|
| 2029 |
@deffn {C API function} int spd_set_spelling(SPDConnection* connection, SPDSpelling type); |
| 2030 |
@findex spd_set_spelling() |
| 2031 |
|
| 2032 |
Switches spelling mode on and off. If set to on, all incoming messages |
| 2033 |
from this particular connection will be processed according to appropriate |
| 2034 |
spelling tables (see spd_set_spelling_table()). |
| 2035 |
|
| 2036 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2037 |
|
| 2038 |
@code{type} is one of the following values: @code{SPD_SPELL_ON}, @code{SPD_SPELL_OFF}. |
| 2039 |
@end deffn |
| 2040 |
|
| 2041 |
@deffn {C API function} int spd_set_voice_type(SPDConnection* connection, SPDVoiceType voice); |
| 2042 |
@findex spd_set_voice_type() |
| 2043 |
@anchor{spd_set_voice_type} |
| 2044 |
|
| 2045 |
Set a preferred symbolic voice. |
| 2046 |
|
| 2047 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2048 |
|
| 2049 |
@code{voice} is one of the following values: @code{SPD_MALE1}, |
| 2050 |
@code{SPD_MALE2}, @code{SPD_MALE3}, @code{SPD_FEMALE1}, @code{SPD_FEMALE2}, |
| 2051 |
@code{SPD_FEMALE3}, @code{SPD_CHILD_MALE}, @code{SPD_CHILD_FEMALE}. |
| 2052 |
|
| 2053 |
@end deffn |
| 2054 |
|
| 2055 |
@deffn {C API function} int spd_set_synthesis_voice(SPDConnection* connection, const char* voice_name); |
| 2056 |
@findex spd_set_voice_type() |
| 2057 |
@anchor{spd_set_synthesis_voice} |
| 2058 |
|
| 2059 |
Set the speech synthesizer voice to use. Please note that synthesis |
| 2060 |
voices are an attribute of the synthesizer, so this setting only takes |
| 2061 |
effect until the output module in use is changed (via |
| 2062 |
@code{spd_set_output_module()} or via @code{spd_set_language}). |
| 2063 |
|
| 2064 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2065 |
|
| 2066 |
@code{voice_name} is any of the voice name values retrieved by @xref{spd_list_synthesis_voices} or @xref{spd_list_synthesis_voices}. |
| 2067 |
|
| 2068 |
@end deffn |
| 2069 |
|
| 2070 |
@deffn {C API function} int spd_set_voice_rate(SPDConnection* connection, int rate); |
| 2071 |
@findex spd_set_voice_rate() |
| 2072 |
|
| 2073 |
Set voice speaking rate. |
| 2074 |
|
| 2075 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2076 |
|
| 2077 |
@code{rate} is a number between -100 and +100 which means |
| 2078 |
the slowest and the fastest speech rate respectively. |
| 2079 |
|
| 2080 |
@end deffn |
| 2081 |
|
| 2082 |
@deffn {C API function} int spd_get_voice_rate(SPDConnection* connection); |
| 2083 |
@findex spd_get_voice_rate() |
| 2084 |
|
| 2085 |
Get voice speaking rate. |
| 2086 |
|
| 2087 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2088 |
|
| 2089 |
It returns the current voice rate. |
| 2090 |
|
| 2091 |
@end deffn |
| 2092 |
|
| 2093 |
@deffn {C API function} int spd_set_voice_pitch(SPDConnection* connection, int pitch); |
| 2094 |
@findex spd_set_voice_pitch() |
| 2095 |
|
| 2096 |
Set voice pitch. |
| 2097 |
|
| 2098 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2099 |
|
| 2100 |
@code{pitch} is a number between -100 and +100, which means the |
| 2101 |
lowest and the highest pitch respectively. |
| 2102 |
|
| 2103 |
@end deffn |
| 2104 |
|
| 2105 |
@deffn {C API function} int spd_get_voice_pitch(SPDConnection* connection); |
| 2106 |
@findex spd_get_voice_pitch() |
| 2107 |
|
| 2108 |
Get voice pitch. |
| 2109 |
|
| 2110 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2111 |
|
| 2112 |
It returns the current voice pitch. |
| 2113 |
|
| 2114 |
@end deffn |
| 2115 |
|
| 2116 |
@deffn {C API function} int spd_set_voice_pitch_range(SPDConnection* connection, int pitch_range); |
| 2117 |
@findex spd_set_voice_pitch() |
| 2118 |
|
| 2119 |
Set voice pitch range. |
| 2120 |
|
| 2121 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2122 |
|
| 2123 |
@code{pitch_range} is a number between -100 and +100, which means the |
| 2124 |
lowest and the highest pitch range respectively. |
| 2125 |
|
| 2126 |
@end deffn |
| 2127 |
|
| 2128 |
@deffn {C API function} int spd_set_volume(SPDConnection* connection, int volume); |
| 2129 |
@findex spd_set_volume() |
| 2130 |
|
| 2131 |
Set the volume of the voice and sounds produced by Speech Dispatcher's output |
| 2132 |
modules. |
| 2133 |
|
| 2134 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2135 |
|
| 2136 |
@code{volume} is a number between -100 and +100 which means |
| 2137 |
the lowest and the loudest voice respectively. |
| 2138 |
|
| 2139 |
@end deffn |
| 2140 |
|
| 2141 |
@deffn {C API function} int spd_get_volume(SPDConnection* connection); |
| 2142 |
@findex spd_get_volume() |
| 2143 |
|
| 2144 |
Get the volume of the voice and sounds produced by Speech Dispatcher's output |
| 2145 |
modules. |
| 2146 |
|
| 2147 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2148 |
|
| 2149 |
It returns the current volume. |
| 2150 |
|
| 2151 |
@end deffn |
| 2152 |
|
| 2153 |
|
| 2154 |
@node Other Functions in C, Information Retrieval Commands in C, Parameter Setting Commands in C, C API |
| 2155 |
@subsection Other Functions |
| 2156 |
|
| 2157 |
@node Information Retrieval Commands in C, Event Notification and Index Marking in C, Other Functions in C, C API |
| 2158 |
@subsection Information Retrieval Commands |
| 2159 |
|
| 2160 |
@deffn {C API function} char** spd_list_modules(SPDConnection* connection) |
| 2161 |
@findex spd_list_modules() |
| 2162 |
@anchor{spd_list_modules} |
| 2163 |
|
| 2164 |
|
| 2165 |
Returns a null-terminated array of identification names of the available |
| 2166 |
output modules. You can subsequently set the desired output module with |
| 2167 |
@xref{spd_set_output_module}. In case of error, the return value is |
| 2168 |
a NULL pointer. |
| 2169 |
|
| 2170 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2171 |
|
| 2172 |
The caller has to call @code{free_spd_modules} to free the returned array. |
| 2173 |
|
| 2174 |
@end deffn |
| 2175 |
|
| 2176 |
@deffn {C API function} char** spd_list_voices(SPDConnection* connection) |
| 2177 |
@findex spd_list_voices() |
| 2178 |
@anchor{spd_list_voices} |
| 2179 |
|
| 2180 |
Returns a null-terminated array of identification names of the |
| 2181 |
symbolic voices. You can subsequently set the desired voice |
| 2182 |
with @xref{spd_set_voice_type}. |
| 2183 |
|
| 2184 |
Please note that this is a fixed list independent of the synthesizer |
| 2185 |
in use. The given voices can be mapped to specific synthesizer voices |
| 2186 |
according to user wish or may, for example, all be mapped to the same |
| 2187 |
voice. To choose directly from the raw list of voices as implemented |
| 2188 |
in the synthesizer, @xref{spd_list_synthesis_voices2} can be used. |
| 2189 |
|
| 2190 |
In case of error, the return value is a NULL pointer. |
| 2191 |
|
| 2192 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2193 |
|
| 2194 |
The caller has to call @code{free_spd_symbolic_voices} to free the returned array. |
| 2195 |
|
| 2196 |
@end deffn |
| 2197 |
|
| 2198 |
@deffn {C API function} char** spd_list_synthesis_voices2(SPDConnection* connection, const char *language, const char *variant) |
| 2199 |
@findex spd_list_synthesis_voices2() |
| 2200 |
@anchor{spd_list_synthesis_voices2} |
| 2201 |
|
| 2202 |
Returns a null-terminated array of identification names of |
| 2203 |
@code{SPDVoice*} structures describing the available voices as given |
| 2204 |
by the synthesizer. You can subsequently set the desired voice with |
| 2205 |
@code{spd_set_synthesis_voice()}. |
| 2206 |
|
| 2207 |
When @code{language} is non-@code{NULL}, only the voices matching this language |
| 2208 |
will be returned. When additionally @code{variant} is non-@code{NULL}, only the |
| 2209 |
voices matching this language and this variant will be returned. |
| 2210 |
|
| 2211 |
@example |
| 2212 |
typedef struct@{ |
| 2213 |
char *name; /* Name of the voice (id) */ |
| 2214 |
char *language; /* 2/3-letter ISO language code, |
| 2215 |
* possibly followed by 2/3-letter ISO region code, |
| 2216 |
* e.g. en-US */ |
| 2217 |
char *variant; /* a not-well defined string describing dialect etc. */ |
| 2218 |
@}SPDVoice; |
| 2219 |
@end example |
| 2220 |
|
| 2221 |
Please note that the list returned is specific to each synthesizer in |
| 2222 |
use (so when you switch to another output module, you must also |
| 2223 |
retrieve a new list). If you want instead to use symbolic voice |
| 2224 |
names which are independent of the synthesizer in use, @xref{spd_list_voices}. |
| 2225 |
|
| 2226 |
In case of error, the return value is a NULL pointer. |
| 2227 |
|
| 2228 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2229 |
|
| 2230 |
The caller has to call @code{free_spd_voices} to free the returned array. |
| 2231 |
|
| 2232 |
@end deffn |
| 2233 |
|
| 2234 |
@deffn {C API function} char** spd_list_synthesis_voices(SPDConnection* connection, const char *language, const char *variant) |
| 2235 |
@findex spd_list_synthesis_voices() |
| 2236 |
@anchor{spd_list_synthesis_voices} |
| 2237 |
|
| 2238 |
This is equivalent to calling @code{spd_list_synthesis_voices2(connection, NULL, NULL)}. |
| 2239 |
|
| 2240 |
@end deffn |
| 2241 |
|
| 2242 |
@node Event Notification and Index Marking in C, History Commands in C, Information Retrieval Commands in C, C API |
| 2243 |
@subsection Event Notification and Index Marking in C |
| 2244 |
|
| 2245 |
When the SSIP connection is run in asynchronous mode, it is possible |
| 2246 |
to register callbacks for all the SSIP event notifications and index |
| 2247 |
mark notifications, as defined in @ref{Message Event Notification |
| 2248 |
and Index Marking,,, ssip, SSIP Documentation} |
| 2249 |
|
| 2250 |
@defvar {C API type} SPDNotification |
| 2251 |
@vindex SPDNotification |
| 2252 |
@anchor{SPDNotification} |
| 2253 |
|
| 2254 |
@code{SPDNotification} is an enum type that represents the possible |
| 2255 |
base notification types that can be assigned to a message. |
| 2256 |
|
| 2257 |
@example |
| 2258 |
typedef enum@{ |
| 2259 |
SPD_BEGIN = 1, |
| 2260 |
SPD_END = 2, |
| 2261 |
SPD_INDEX_MARKS = 4, |
| 2262 |
SPD_CANCEL = 8, |
| 2263 |
SPD_PAUSE = 16, |
| 2264 |
SPD_RESUME = 32 |
| 2265 |
@}SPDNotification; |
| 2266 |
@end example |
| 2267 |
@end defvar |
| 2268 |
|
| 2269 |
There are currently two types of callbacks in the C API. |
| 2270 |
|
| 2271 |
@defvar {C API type} SPDCallback |
| 2272 |
@vindex SPDCallback |
| 2273 |
@anchor{SPDCallback} |
| 2274 |
@code{void (*SPDCallback)(size_t msg_id, size_t client_id, SPDNotificationType state);} |
| 2275 |
|
| 2276 |
This one is used for notifications about the events: @code{BEGIN}, @code{END}, @code{PAUSE} |
| 2277 |
and @code{RESUME}. When the callback is called, it provides three parameters for the event. |
| 2278 |
|
| 2279 |
@code{msg_id} unique identification number of the message the notification is about. |
| 2280 |
|
| 2281 |
@code{client_id} specifies the unique identification number of the client who sent the |
| 2282 |
message. This is usually the same connection as the connection which registered this |
| 2283 |
callback, and therefore uninteresting. However, in some special cases it might be useful |
| 2284 |
to register this callback for other SSIP connections, or register the same callback for |
| 2285 |
several connections originating from the same application. |
| 2286 |
|
| 2287 |
@code{state} is the @code{SPD_Notification} type of this notification. @xref{SPDNotification}. |
| 2288 |
@end defvar |
| 2289 |
|
| 2290 |
@defvar {C API type} SPDCallbackIM |
| 2291 |
@vindex SPDCallbackIM |
| 2292 |
@code{void (*SPDCallbackIM)(size_t msg_id, size_t client_id, SPDNotificationType state, |
| 2293 |
char *index_mark);} |
| 2294 |
|
| 2295 |
@code{SPDCallbackIM} is used for notifications about index marks that have been reached |
| 2296 |
in the message. (A way to specify index marks is e.g. through the SSML element |
| 2297 |
<mark/> in ssml mode.) |
| 2298 |
|
| 2299 |
The syntax and meaning of these parameters are the same as for @ref{SPDCallback} |
| 2300 |
except for the additional parameter @code{index_mark}. |
| 2301 |
|
| 2302 |
@code{index_mark} is a NULL terminated string associated with the index mark. Please |
| 2303 |
note that this string is specified by client application and therefore it needn't be |
| 2304 |
unique. |
| 2305 |
@end defvar |
| 2306 |
|
| 2307 |
One or more callbacks can be supplied for a given @code{SPDConnection*} connection by |
| 2308 |
assigning the values of pointers to the appropriate functions to the following connection |
| 2309 |
members: |
| 2310 |
|
| 2311 |
@example |
| 2312 |
SPDCallback callback_begin; |
| 2313 |
SPDCallback callback_end; |
| 2314 |
SPDCallback callback_cancel; |
| 2315 |
SPDCallback callback_pause; |
| 2316 |
SPDCallback callback_resume; |
| 2317 |
SPDCallbackIM callback_im; |
| 2318 |
@end example |
| 2319 |
|
| 2320 |
There are three settings commands which will turn notifications on and |
| 2321 |
off for the current SSIP connection and cause the callbacks to be called |
| 2322 |
when the event is registered by Speech Dispatcher. |
| 2323 |
|
| 2324 |
@deffn {C API function} int spd_set_notification_on(SPDConnection* connection, SPDNotification notification); |
| 2325 |
@findex spd_set_notification_on |
| 2326 |
@end deffn |
| 2327 |
@deffn {C API function} int spd_set_notification_off(SPDConnection* connection, SPDNotification notification); |
| 2328 |
@findex spd_set_notification_off |
| 2329 |
@end deffn |
| 2330 |
@deffn {C API function} int spd_set_notification(SPDConnection* connection, SPDNotification notification, const char* state); |
| 2331 |
@findex spd_set_notification |
| 2332 |
|
| 2333 |
These functions will set the notification specified by the parameter |
| 2334 |
@code{notification} on or off (or to the given value) |
| 2335 |
respectively. Note that it is only safe to call these functions after |
| 2336 |
the appropriate callback functions have been set in the @code{SPDCallback} |
| 2337 |
structure. Doing otherwise is not considered an error, but the |
| 2338 |
application might miss some events due to callback functions not being |
| 2339 |
executed (e.g. the client might receive an @code{END} event without |
| 2340 |
receiving the corresponding @code{BEGIN} event in advance. |
| 2341 |
|
| 2342 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2343 |
|
| 2344 |
@code{notification} is the requested type of notifications that should be reported by SSIP. @xref{SPDNotification}. |
| 2345 |
Note that also '|' combinations are possible, as illustrated in the example below. |
| 2346 |
|
| 2347 |
@code{state} must be either the string ``on'' or ``off'', for switching the given notification on or off. |
| 2348 |
|
| 2349 |
@end deffn |
| 2350 |
|
| 2351 |
The following example shows how to use callbacks for the simple |
| 2352 |
purpose of playing a message and waiting until its end. (Please note |
| 2353 |
that checks of return values in this example as well as other code |
| 2354 |
not directly related to index marking, have been removed for the purpose |
| 2355 |
of clarity.) |
| 2356 |
|
| 2357 |
@example |
| 2358 |
#include <semaphore.h> |
| 2359 |
|
| 2360 |
sem_t semaphore; |
| 2361 |
|
| 2362 |
/* Callback for Speech Dispatcher notifications */ |
| 2363 |
void end_of_speech(size_t msg_id, size_t client_id, SPDNotificationType type) |
| 2364 |
@{ |
| 2365 |
/* We don't check msg_id here since we will only send one |
| 2366 |
message. */ |
| 2367 |
|
| 2368 |
/* Callbacks are running in a separate thread, so let the |
| 2369 |
(sleeping) main thread know about the event and wake it up. */ |
| 2370 |
sem_post(&semaphore); |
| 2371 |
@} |
| 2372 |
|
| 2373 |
int |
| 2374 |
main(int argc, char **argv) |
| 2375 |
@{ |
| 2376 |
SPDConnection *conn; |
| 2377 |
|
| 2378 |
sem_init(&semaphore, 0, 0); |
| 2379 |
|
| 2380 |
/* Open Speech Dispatcher connection in THREADED mode. */ |
| 2381 |
conn = spd_open("say","main", NULL, SPD_MODE_THREADED); |
| 2382 |
|
| 2383 |
/* Set callback handler for 'end' and 'cancel' events. */ |
| 2384 |
conn->callback_end = conn->callback_cancel = end_of_speech; |
| 2385 |
|
| 2386 |
/* Ask Speech Dispatcher to notify us about these events. */ |
| 2387 |
spd_set_notification_on(conn, SPD_END); |
| 2388 |
spd_set_notification_on(conn, SPD_CANCEL); |
| 2389 |
|
| 2390 |
/* Say our message. */ |
| 2391 |
spd_sayf(conn, SPD_MESSAGE, "%s", argv[1]); |
| 2392 |
|
| 2393 |
/* Wait for 'end' or 'cancel' of the sent message. |
| 2394 |
By SSIP specifications, we are guaranteed to get |
| 2395 |
one of these two eventually. */ |
| 2396 |
sem_wait(&semaphore); |
| 2397 |
|
| 2398 |
return 0; |
| 2399 |
@} |
| 2400 |
@end example |
| 2401 |
|
| 2402 |
@node History Commands in C, Direct SSIP Communication in C, Event Notification and Index Marking in C, C API |
| 2403 |
@subsection History Commands |
| 2404 |
@findex spd_history_select_client() |
| 2405 |
@findex spd_get_client_list() |
| 2406 |
@findex spd_get_message_list_fd() |
| 2407 |
|
| 2408 |
@node Direct SSIP Communication in C, , History Commands in C, C API |
| 2409 |
@subsection Direct SSIP Communication in C |
| 2410 |
|
| 2411 |
It might happen that you want to use some SSIP function that is not |
| 2412 |
available through a library or you may want to use an available |
| 2413 |
function in a different manner. (If you think there is something |
| 2414 |
missing in a library or you have some useful comment on the |
| 2415 |
available functions, please let us know.) For this purpose, there are |
| 2416 |
a few functions that will allow you to send arbitrary SSIP commands on |
| 2417 |
your connection and read the replies. |
| 2418 |
|
| 2419 |
@deffn {C API function} int spd_execute_command(SPDConnection* connection, const char *command); |
| 2420 |
@findex spd_execute_command() |
| 2421 |
|
| 2422 |
You can send an arbitrary SSIP command specified in the parameter @code{command}. |
| 2423 |
|
| 2424 |
If the command is successful, the function returns a 0. If there is no such |
| 2425 |
command or the command failed for some reason, it returns -1. |
| 2426 |
|
| 2427 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2428 |
|
| 2429 |
@code{command} is a null terminated string containing a full SSIP command |
| 2430 |
without the terminating sequence @code{\r\n}. |
| 2431 |
|
| 2432 |
For example: |
| 2433 |
@example |
| 2434 |
spd_execute_command(fd, "SET SELF RATE 60"); |
| 2435 |
spd_execute_command(fd, "SOUND_ICON bell"); |
| 2436 |
@end example |
| 2437 |
|
| 2438 |
It's not possible to use this function for compound commands like @code{SPEAK} |
| 2439 |
where you are receiving more than one reply. If this is your case, please |
| 2440 |
see `spd_send_data()'. |
| 2441 |
@end deffn |
| 2442 |
|
| 2443 |
@deffn {C API function} char* spd_send_data(SPDConnection* connection, const char *message, int wfr); |
| 2444 |
@findex spd_send_data() |
| 2445 |
|
| 2446 |
You can send an arbitrary SSIP string specified in the parameter @code{message} |
| 2447 |
and, if specified, wait for the reply. The string can be any SSIP command, but |
| 2448 |
it can also be textual data or a command parameter. |
| 2449 |
|
| 2450 |
If @code{wfr} (wait for reply) is set to SPD_WAIT_REPLY, you will receive the reply string |
| 2451 |
as the return value. If wfr is set to SPD_NO_REPLY, the return value is a NULL pointer. |
| 2452 |
If wfr is set to SPD_WAIT_REPLY, you should always free the returned string. |
| 2453 |
|
| 2454 |
@code{connection} is the SPDConnection* connection created by spd_open(). |
| 2455 |
|
| 2456 |
@code{message} is a null terminated string containing a full SSIP |
| 2457 |
string. If this is a complete SSIP command, it must include the full |
| 2458 |
terminating sequence @code{\r\n}. |
| 2459 |
|
| 2460 |
@code{wfr} is either SPD_WAIT_REPLY (integer value of 1) or SPD_NO_REPLY (0). |
| 2461 |
This specifies if you expect to get a reply on the sent data according to SSIP. |
| 2462 |
For example, if you are sending ordinary text inside a @code{SPEAK} command, |
| 2463 |
you don't expect to get a reply, but you expect a reply after sending the final |
| 2464 |
sequence @code{\r\n.\r\n} of the multi-line command. |
| 2465 |
|
| 2466 |
For example (simplified by not checking and freeing the returned strings): |
| 2467 |
@example |
| 2468 |
spd_send_data(conn, "SPEAK", SPD_WAIT_REPLY); |
| 2469 |
spd_send_data(conn, "Hello world!\n", SPD_NO_REPLY); |
| 2470 |
spd_send_data(conn, "How are you today?!", SPD_NO_REPLY); |
| 2471 |
spd_send_data(conn, "\r\n.\r\n.", SPD_WAIT_REPLY); |
| 2472 |
@end example |
| 2473 |
|
| 2474 |
@end deffn |
| 2475 |
|
| 2476 |
|
| 2477 |
@node Python API, Guile API, C API, Client Programming |
| 2478 |
@section Python API |
| 2479 |
|
| 2480 |
There is a full Python API available in @file{src/api/python/speechd/} in |
| 2481 |
the source tree. Please see the Python docstrings for full reference |
| 2482 |
about the available objects and methods. |
| 2483 |
|
| 2484 |
Simple Python client: |
| 2485 |
@example |
| 2486 |
import speechd |
| 2487 |
client = speechd.SSIPClient('test') |
| 2488 |
client.set_output_module('festival') |
| 2489 |
client.set_language('en-US') |
| 2490 |
client.set_punctuation(speechd.PunctuationMode.SOME) |
| 2491 |
client.speak("Hello World!") |
| 2492 |
client.close() |
| 2493 |
@end example |
| 2494 |
|
| 2495 |
The Python API respects the environment variables |
| 2496 |
@var{SPEECHD_ADDRESS} it the communication address is not specified |
| 2497 |
explicitly (see @code{SSIPClient} constructor arguments). |
| 2498 |
|
| 2499 |
Implementation of callbacks within the Python API tries to hide the |
| 2500 |
low level details of SSIP callback handling and provide a convenient |
| 2501 |
Pythonic interface. You just pass a callable object (function) to the |
| 2502 |
@code{speak()} method and this function will be called whenever an |
| 2503 |
event occurs for the corresponding message. |
| 2504 |
|
| 2505 |
Callback example: |
| 2506 |
@example |
| 2507 |
import speechd, time |
| 2508 |
called = [] |
| 2509 |
client = speechd.SSIPClient('callback-test') |
| 2510 |
client.speak("Hi!", callback=lambda cb_type: called.append(cb_type)) |
| 2511 |
time.sleep(2) # Wait for the events to happen. |
| 2512 |
print "Called callbacks:", called |
| 2513 |
client.close() |
| 2514 |
@end example |
| 2515 |
|
| 2516 |
Real-world callback functions will most often need some sort of |
| 2517 |
context information to be able to distinguish for which message the |
| 2518 |
callback was called. This can be simply done in Python. The |
| 2519 |
following example uses the actual message text as the context |
| 2520 |
information within the callback function. |
| 2521 |
|
| 2522 |
Callback context example: |
| 2523 |
@example |
| 2524 |
import speechd, time |
| 2525 |
|
| 2526 |
class CallbackExample(object): |
| 2527 |
def __init__(self): |
| 2528 |
self._client = speechd.SSIPClient('callback-test') |
| 2529 |
|
| 2530 |
def speak(self, text): |
| 2531 |
def callback(callback_type): |
| 2532 |
if callback_type == speechd.CallbackType.BEGIN: |
| 2533 |
print "Speech started:", text |
| 2534 |
elif callback_type == speechd.CallbackType.END: |
| 2535 |
print "Speech completed:", text |
| 2536 |
elif callback_type == speechd.CallbackType.CANCEL: |
| 2537 |
print "Speech interrupted:", text |
| 2538 |
self._client.speak(text, callback=callback, |
| 2539 |
event_types=(speechd.CallbackType.BEGIN, |
| 2540 |
speechd.CallbackType.CANCEL, |
| 2541 |
speechd.CallbackType.END)) |
| 2542 |
|
| 2543 |
def go(self): |
| 2544 |
self.speak("Hi!") |
| 2545 |
self.speak("How are you?") |
| 2546 |
time.sleep(4) # Wait for the events to happen. |
| 2547 |
self._client.close() |
| 2548 |
|
| 2549 |
CallbackExample().go() |
| 2550 |
@end example |
| 2551 |
|
| 2552 |
@emph{Important notice:} The callback is called in Speech Dispatcher |
| 2553 |
listener thread. No subsequent Speech Dispatcher interaction is |
| 2554 |
allowed from within the callback invocation. If you need to do |
| 2555 |
something more complicated, do it in another thread to prevent |
| 2556 |
deadlocks in SSIP communication. |
| 2557 |
|
| 2558 |
@node Guile API, Common Lisp API, Python API, Client Programming |
| 2559 |
@section Guile API |
| 2560 |
|
| 2561 |
The Guile API can be found @file{src/guile/} in |
| 2562 |
the source tree, however it's still considered to be |
| 2563 |
at the experimental stage. Please read @file{src/guile/README}. |
| 2564 |
|
| 2565 |
@node Common Lisp API, Golang API, Guile API, Client Programming |
| 2566 |
@section Common Lisp API |
| 2567 |
|
| 2568 |
The Common Lisp API can be found @file{src/cl/} in |
| 2569 |
the source tree, however it's still considered to be |
| 2570 |
at the experimental stage. Please read @file{src/cl/README}. |
| 2571 |
|
| 2572 |
@node Golang API, Autospawning, Common Lisp API, Client Programming |
| 2573 |
@section Golang API |
| 2574 |
|
| 2575 |
A golang interface is also available on |
| 2576 |
@uref{https://github.com/ilyapashuk/go-speechd}. |
| 2577 |
|
| 2578 |
@node Autospawning, , Common Lisp API, Client Programming |
| 2579 |
@section Autospawning |
| 2580 |
|
| 2581 |
It is suggested that client libraries offer an autospawn functionality |
| 2582 |
to automatically start the server process when connecting locally and if |
| 2583 |
it is not already running. E.g. if the client application starts and |
| 2584 |
Speech Dispatcher is not running already, the client will start Speech |
| 2585 |
Dispatcher. |
| 2586 |
|
| 2587 |
The library API should provide a possibility to turn this |
| 2588 |
functionality off, but we suggest to set the default behavior to |
| 2589 |
autospawn. |
| 2590 |
|
| 2591 |
Autospawn is performed by executing Speech Dispatcher with the --spawn |
| 2592 |
parameter under the same user and permissions as the client process: |
| 2593 |
|
| 2594 |
@example |
| 2595 |
speech-dispatcher --spawn |
| 2596 |
@end example |
| 2597 |
|
| 2598 |
With the @code{--spawn} parameter, the process will start and return |
| 2599 |
with an exit code of 0 only if a) it is not already running (pidfile |
| 2600 |
check) b) the server doesn't have autospawn disabled in its |
| 2601 |
configuration c) no other error preventing the start |
| 2602 |
occurs. Otherwise, Speech Dispatcher is not started and the error code |
| 2603 |
of 1 is returned. |
| 2604 |
|
| 2605 |
The location of the @code{speech-dispatcher} command should be obtained |
| 2606 |
from the @code{SPEECHD_CMD} environment variable if defined, and otherwise |
| 2607 |
fallback to the @code{SPD_SPAWN_CMD} compile-time constant, i.e. |
| 2608 |
@code{$bindir/speech-dispatcher}. |
| 2609 |
|
| 2610 |
The client library should redirect its stdout and stderr outputs |
| 2611 |
either to nowhere or to its logging system. It should subsequently |
| 2612 |
completely detach from the newly spawned process. |
| 2613 |
|
| 2614 |
Please see how autospawn is implemented in the C API and in the Python |
| 2615 |
API for an example. |
| 2616 |
|
| 2617 |
@node Server Programming, Download and Contact, Client Programming, Top |
| 2618 |
@chapter Server Programming |
| 2619 |
|
| 2620 |
@menu |
| 2621 |
* Server Core:: Internal structure and functionality overview. |
| 2622 |
* Output Modules:: Plugins for various speech synthesizers. |
| 2623 |
@end menu |
| 2624 |
|
| 2625 |
@node Server Core, Output Modules, Server Programming, Server Programming |
| 2626 |
@section Server Core |
| 2627 |
|
| 2628 |
The main documentation for the server core is the code itself. This section |
| 2629 |
is only a general introduction intended to give you some basic information |
| 2630 |
and hints where to look for things. If you are going to make some modifications |
| 2631 |
in the server core, we will be happy if you get in touch with us on |
| 2632 |
@email{speechd-discuss@@nongnu.org}. |
| 2633 |
|
| 2634 |
The server core is composed of two main parts, each of them implemented |
| 2635 |
in a separate thread. The @emph{server part} handles the communication |
| 2636 |
with clients and, with the desired configuration options, stores the messages |
| 2637 |
in the priority queue. The @emph{speaking part} takes care of |
| 2638 |
communicating with the output modules, pulls messages out of the priority |
| 2639 |
queue at the correct time and sends them to the appropriate synthesizer. |
| 2640 |
|
| 2641 |
Synchronization between these two parts is done by thread mutexes. |
| 2642 |
Additionally, synchronization of the speaking part from both sides |
| 2643 |
(server part, output modules) is done via a SYSV/IPC semaphore. |
| 2644 |
|
| 2645 |
@subheading Server part |
| 2646 |
|
| 2647 |
After switching to the daemon mode (if required), it reads configuration |
| 2648 |
files and initializes the speaking part. Then it opens the socket |
| 2649 |
and waits for incoming data. This is implemented mainly in |
| 2650 |
@file{src/server/speechd.c} and @file{src/server/server.c}. |
| 2651 |
|
| 2652 |
There are three types of events: new client connects to speechd, |
| 2653 |
old client disconnects, or a client sends some data. In the third |
| 2654 |
case, the data is passed to the @code{parse()} function defined |
| 2655 |
in @file{src/server/parse.c}. |
| 2656 |
|
| 2657 |
If the incoming data is a new message, it's stored in a |
| 2658 |
queue according to its priority. If it is SSIP |
| 2659 |
commands, it's handled by the appropriate handlers. |
| 2660 |
Handling of the @code{SET} family of commands can be found |
| 2661 |
in @file{src/server/set.c} and @code{HISTORY} commands are |
| 2662 |
processed in @file{src/server/history.c}. |
| 2663 |
|
| 2664 |
All reply messages of SSIP are defined in @file{src/server/msg.h}. |
| 2665 |
|
| 2666 |
@subheading Speaking part |
| 2667 |
|
| 2668 |
This thread, the function @code{speak()} defined in |
| 2669 |
@file{src/server/speaking.c}, is created from the server part process |
| 2670 |
shortly after initialization. Then it enters an infinite loop and |
| 2671 |
waits on a SYSV/IPC semaphore until one of the following actions |
| 2672 |
happen: |
| 2673 |
|
| 2674 |
@itemize @bullet |
| 2675 |
@item |
| 2676 |
The server adds a new message to the queue of messages waiting |
| 2677 |
to be said. |
| 2678 |
@item |
| 2679 |
The currently active output module signals that the message |
| 2680 |
that was being spoken is done. |
| 2681 |
@item |
| 2682 |
Pause or resume is requested. |
| 2683 |
@end itemize |
| 2684 |
|
| 2685 |
After handling the rest of the priority interaction (like actions |
| 2686 |
needed to repeat the last priority progress message) it decides |
| 2687 |
which action should be performed. Usually it's picking up |
| 2688 |
a message from the queue and sending it to the desired output |
| 2689 |
module (synthesizer), but sometimes it's handling the pause |
| 2690 |
or resume requests, and sometimes it's doing nothing. |
| 2691 |
|
| 2692 |
As said before, this is the part of Speech Dispatcher that |
| 2693 |
talks to the output modules. It does so by using the output |
| 2694 |
interface defined in @file{src/server/output.c}. |
| 2695 |
|
| 2696 |
@node Output Modules, , Server Core, Server Programming |
| 2697 |
@section Output Modules |
| 2698 |
|
| 2699 |
@menu |
| 2700 |
* Basic Structure:: The definition of an output module. |
| 2701 |
* Communication Protocol for Output Modules:: |
| 2702 |
* How to Write New Output Module:: How to include support for new synthesizers |
| 2703 |
* The Skeleton of a Bare Output Module:: |
| 2704 |
* The Skeleton of an Output Module:: |
| 2705 |
* Output Module Functions:: |
| 2706 |
* Module Utils Functions and Macros:: |
| 2707 |
* Index Marks in Output Modules:: |
| 2708 |
@end menu |
| 2709 |
|
| 2710 |
@node Basic Structure, Communication Protocol for Output Modules, Output Modules, Output Modules |
| 2711 |
@subsection Basic Structure |
| 2712 |
|
| 2713 |
Speech Dispatcher output modules are independent applications that, |
| 2714 |
using a simple common communication protocol, read commands from |
| 2715 |
standard input and then output replies on standard output, |
| 2716 |
communicating the requests to the particular software or hardware |
| 2717 |
synthesizer. Everything the output module writes on standard output |
| 2718 |
or reads from standard input should conform to the specifications |
| 2719 |
of the communication protocol. Additionally, standard error output |
| 2720 |
is used for logging of the modules. |
| 2721 |
|
| 2722 |
Output module binaries are usually located in |
| 2723 |
@file{libexec/speech-dispatcher-modules/} or in user's |
| 2724 |
@file{~/.local/libexec/speech-dispatcher-modules} |
| 2725 |
and are loaded automatically when Speech |
| 2726 |
Dispatcher starts, according to configuration. Their standard |
| 2727 |
input/output/error output is redirected to a pipe to Speech Dispatcher |
| 2728 |
and this way both sides can communicate. |
| 2729 |
|
| 2730 |
When the modules start, they are passed the name of a configuration file |
| 2731 |
that should be used for this particular output module. |
| 2732 |
|
| 2733 |
Each output module is started by Speech Dispatcher as: |
| 2734 |
|
| 2735 |
@example |
| 2736 |
my_module "configfile" |
| 2737 |
@end example |
| 2738 |
|
| 2739 |
where @code{configfile} is the full path to the desired configuration |
| 2740 |
file that the output module should parse. |
| 2741 |
|
| 2742 |
@node Communication Protocol for Output Modules, How to Write New Output Module, Basic Structure, Output Modules |
| 2743 |
@subsection Communication Protocol for Output Modules |
| 2744 |
|
| 2745 |
The protocol by which the output modules communicate on standard |
| 2746 |
input/output is based on @ref{Top,,SSIP,ssip, SSIP |
| 2747 |
Documentation}, although it is highly simplified and a little bit |
| 2748 |
modified for the different purpose here. Another difference |
| 2749 |
is that event notification is obligatory in modules communication, |
| 2750 |
while in SSIP, this is an optional feature. This is because Speech |
| 2751 |
Dispatcher has to know all the events happening in the output modules |
| 2752 |
for the purpose of synchronization of various messages. |
| 2753 |
|
| 2754 |
Since it's very similar to SSIP, @ref{Top,,General Rules,ssip, SSIP |
| 2755 |
Documentation}, for a general description of what the protocol looks |
| 2756 |
like. One of the exceptions is that since the output modules |
| 2757 |
communicate on standard input/output, we use only @code{LF} as the |
| 2758 |
line separator. |
| 2759 |
|
| 2760 |
The return values are: |
| 2761 |
@itemize |
| 2762 |
@item 2xx OK |
| 2763 |
@item 3xx CLIENT ERROR or BAD SYNTAX or INVALID VALUE |
| 2764 |
@item 4xx OUTPUT MODULE ERROR or INTERNAL ERROR |
| 2765 |
|
| 2766 |
@item 700 EVENT INDEX MARK |
| 2767 |
@item 701 EVENT BEGIN |
| 2768 |
@item 702 EVENT END |
| 2769 |
@item 703 EVENT STOP |
| 2770 |
@item 704 EVENT PAUSE |
| 2771 |
@item 705 AUDIO |
| 2772 |
@item 706 ICON |
| 2773 |
@end itemize |
| 2774 |
|
| 2775 |
@table @code |
| 2776 |
@item SPEAK |
| 2777 |
Start receiving a text message in the SSML format and synthesize it. |
| 2778 |
After sending a reply to the command, output module waits for the text |
| 2779 |
of the message. The text can spread over any number of lines and is |
| 2780 |
finished by an end of line marker followed by the line containing the |
| 2781 |
single character @code{.} (dot). Thus the complete character sequence |
| 2782 |
closing the input text is @code{LF . LF}. If any line within the sent |
| 2783 |
text contains only a dot, an extra dot should be prepended before it. |
| 2784 |
|
| 2785 |
During reception of the text message, output module doesn't send a |
| 2786 |
response to the particular lines sent. The response line is sent only |
| 2787 |
immediately after the @code{SPEAK} command and after receiving the |
| 2788 |
closing dot line. This doesn't provide any means of synchronization, |
| 2789 |
instead, event notification is used for this purpose. |
| 2790 |
|
| 2791 |
There is no explicit upper limit on the size of the text. |
| 2792 |
|
| 2793 |
If the @code{SPEAK} command is received while the output module |
| 2794 |
is already speaking, it is considered an error. |
| 2795 |
|
| 2796 |
Example: |
| 2797 |
@example |
| 2798 |
SPEAK |
| 2799 |
202 OK SEND DATA |
| 2800 |
<speak> |
| 2801 |
Hello, GNU! |
| 2802 |
</speak> |
| 2803 |
. |
| 2804 |
200 OK SPEAKING |
| 2805 |
@end example |
| 2806 |
|
| 2807 |
After receiving the full text (or the first part of it), the output |
| 2808 |
module is supposed to start synthesizing it and take care of |
| 2809 |
delivering it to an audio device. When (or just before) the first |
| 2810 |
synthesized samples are delivered to the audio and start playing, the |
| 2811 |
output module must send the @code{BEGIN} event over the communication |
| 2812 |
socket to Speech Dispatcher, @xref{Events notification and index |
| 2813 |
marking}. After the audio stops playing, the event @code{STOP}, |
| 2814 |
@code{PAUSE} or @code{END} must be delivered to Speech |
| 2815 |
Dispatcher. Additionally, if supported by the given synthesizer, the |
| 2816 |
output module can issue events associated with the included SSML index |
| 2817 |
marks when they are reached in the audio output. |
| 2818 |
|
| 2819 |
@item CHAR |
| 2820 |
Synthesize a character. If the synthesizer supports a different behavior |
| 2821 |
for the event of ``character'', this should be used. |
| 2822 |
|
| 2823 |
It works like the command @code{SPEAK} above, except that the argument |
| 2824 |
has to be exactly one line long. It contains the UTF-8 form of exactly |
| 2825 |
one character. |
| 2826 |
|
| 2827 |
@item KEY |
| 2828 |
Synthesize a key name. If the synthesizer supports a different behavior |
| 2829 |
for the event of ``key name'', this should be used. |
| 2830 |
|
| 2831 |
It works like the command @code{SPEAK} above, except that the argument |
| 2832 |
has to be exactly one line long. @xref{Top, ,SSIP KEY,ssip, SSIP |
| 2833 |
Documentation}, for the description of the allowed arguments. |
| 2834 |
|
| 2835 |
@item SOUND_ICON |
| 2836 |
Produce a sound icon. According to the configuration of the particular |
| 2837 |
synthesizer, this can produce either a sound (e.g. .wav) or synthesize |
| 2838 |
some text. |
| 2839 |
|
| 2840 |
It works like the command @code{SPEAK} above, except that the argument |
| 2841 |
has to be exactly one line long. It contains the symbolic name of the |
| 2842 |
icon that should be said. @xref{Top,,SSIP SOUND_ICON, ssip, SSIP |
| 2843 |
Documentation}, for more detailed description of the sound icons |
| 2844 |
mechanism. |
| 2845 |
|
| 2846 |
@item STOP |
| 2847 |
Immediately stop speaking on the output device and cancel synthesizing |
| 2848 |
the current message so that the output module is prepared to receive a |
| 2849 |
new message. If there is currently no message being synthesized, it is |
| 2850 |
not considered an error to call @code{STOP} anyway. |
| 2851 |
|
| 2852 |
This command is asynchronous. The output module is not supposed to |
| 2853 |
send any reply (not even error reply). |
| 2854 |
|
| 2855 |
It should return immediately, although stopping the synthesizer may |
| 2856 |
require a little bit more time. The module must issue one of the events |
| 2857 |
@code{STOPPED} or @code{END} when the module is finally |
| 2858 |
stopped. @code{END} is issued when the playing stopped by itself |
| 2859 |
before the module could terminate it or if the architecture of the |
| 2860 |
output module doesn't allow it to decide, otherwise @code{STOPPED} |
| 2861 |
should be used. |
| 2862 |
|
| 2863 |
@example |
| 2864 |
STOP |
| 2865 |
@end example |
| 2866 |
|
| 2867 |
@item PAUSE |
| 2868 |
Stop speaking the current message at a place where we can exactly |
| 2869 |
determine the position (preferably after a @code{__spd_} index mark). This |
| 2870 |
doesn't have to be immediate and can be delayed even for a few |
| 2871 |
seconds. (Knowing the position exactly is important so that we can |
| 2872 |
later continue the message without gaps or overlapping.) It doesn't do |
| 2873 |
anything else (like storing the message etc.). |
| 2874 |
|
| 2875 |
This command is asynchronous. The output module is not supposed to |
| 2876 |
send any reply (not even error reply). |
| 2877 |
|
| 2878 |
For example: |
| 2879 |
@example |
| 2880 |
PAUSE |
| 2881 |
@end example |
| 2882 |
|
| 2883 |
@item SET |
| 2884 |
Set one of several speech parameters for the future messages. |
| 2885 |
|
| 2886 |
Each of the parameters is written on a single line in the form |
| 2887 |
@example |
| 2888 |
name=value |
| 2889 |
@end example |
| 2890 |
where @code{value} can be either a number or a string, depending upon |
| 2891 |
the name of the parameter. |
| 2892 |
|
| 2893 |
The @code{SET} environment is terminated by a dot on a single line. |
| 2894 |
Thus the complete character sequence closing the input text is |
| 2895 |
@code{LF . LF} |
| 2896 |
|
| 2897 |
During reception of the settings, output module doesn't send any |
| 2898 |
response to the particular lines sent. The response line is sent only |
| 2899 |
immediately after the @code{SET} command and after receiving the |
| 2900 |
closing dot line. |
| 2901 |
|
| 2902 |
The available parameters that accept numerical values are @code{rate}, |
| 2903 |
@code{pitch} and @code{pitch_range}. |
| 2904 |
|
| 2905 |
The available parameters that accept string values are |
| 2906 |
@code{punctuation_mode}, @code{spelling_mode}, @code{cap_let_recogn}, |
| 2907 |
@code{voice}, and @code{language}. The arguments are the same as for the |
| 2908 |
corresponding SSIP commands, except that they are written with small |
| 2909 |
letters. @xref{Top,,Parameter Setting Commands,ssip, SSIP |
| 2910 |
Documentation}. The conversion between these string values and the |
| 2911 |
corresponding C enum variables can be easily done using |
| 2912 |
@file{src/common/fdsetconv.c}. |
| 2913 |
|
| 2914 |
Not all of these parameters must be set and the value of the string |
| 2915 |
arguments can also be @code{NULL}. If some of the parameters aren't |
| 2916 |
set, the output module should use its default. |
| 2917 |
|
| 2918 |
It's not necessary to set these parameters on the synthesizer right |
| 2919 |
away, instead, it can be postponed until some message to be spoken arrives. |
| 2920 |
|
| 2921 |
Here is an example: |
| 2922 |
@example |
| 2923 |
SET |
| 2924 |
203 OK RECEIVING SETTINGS |
| 2925 |
rate=20 |
| 2926 |
pitch=-10 |
| 2927 |
pitch_range=50 |
| 2928 |
punctuation_mode=all |
| 2929 |
spelling_mode=on |
| 2930 |
punctuation_some=NULL |
| 2931 |
. |
| 2932 |
203 OK SETTINGS RECEIVED |
| 2933 |
@end example |
| 2934 |
|
| 2935 |
@item AUDIO |
| 2936 |
Audio has exactly the same structure as @code{SET}, but is transmitted |
| 2937 |
only once immediately after @code{INIT} to transmit the requested audio |
| 2938 |
parameters and tell the output module to open the audio device. |
| 2939 |
|
| 2940 |
Here is an example: |
| 2941 |
@example |
| 2942 |
AUDIO |
| 2943 |
207 OK RECEIVING AUDIO SETTINGS |
| 2944 |
audio_output_method=pulse |
| 2945 |
audio_pulse_device=default |
| 2946 |
. |
| 2947 |
203 OK AUDIO INITIALIZED |
| 2948 |
@end example |
| 2949 |
|
| 2950 |
@item QUIT |
| 2951 |
Terminates the output module. It should send the response, deallocate |
| 2952 |
all the resources, close all descriptors, terminate all child |
| 2953 |
processes etc. Then the output module should exit itself. |
| 2954 |
|
| 2955 |
@example |
| 2956 |
QUIT |
| 2957 |
210 OK QUIT |
| 2958 |
@end example |
| 2959 |
@end table |
| 2960 |
|
| 2961 |
@subsubsection Events notification and index marking |
| 2962 |
@anchor{Events notification and index marking} |
| 2963 |
|
| 2964 |
Each output module must take care of sending asynchronous |
| 2965 |
notifications whenever the synthesizer (or the module) starts or stops |
| 2966 |
output audio on the speakers. Additionally, whenever possible, the |
| 2967 |
output module should report back to Speech Dispatcher index marks |
| 2968 |
found in the incoming SSML text whenever they are reached while |
| 2969 |
speaking. See SSML specifications for more details about the |
| 2970 |
@code{mark} element |
| 2971 |
|
| 2972 |
Event and index mark notifications are reported by simply writing them |
| 2973 |
to the standard output. An event notification must never get in |
| 2974 |
between synchronous commands (those which require a reply) and their |
| 2975 |
reply. Before Speech Dispatcher sends any new requests (like |
| 2976 |
@code{SET}, @code{SPEAK} etc.) it waits for the previous request to be |
| 2977 |
terminated by the output module by signalling @code{STOP}, @code{END} |
| 2978 |
or @code{PAUSE} index marks. So the only thing the output module must |
| 2979 |
ensure in order to satisfy this requirement is that it doesn't send |
| 2980 |
any index marks until it acknowledges the receival of the new message |
| 2981 |
via @code{200 OK SPEAKING}. It must also ensure that index marks |
| 2982 |
written to the pipe are well ordered -- of course it doesn't make any |
| 2983 |
sense and it is an error to send any index marks after @code{STOP}, |
| 2984 |
@code{END} or @code{PAUSE} is sent. |
| 2985 |
|
| 2986 |
|
| 2987 |
@table @code |
| 2988 |
|
| 2989 |
@item BEGIN |
| 2990 |
|
| 2991 |
This event must be issued whenever the module starts to speak the |
| 2992 |
given message. If this is not possible, it can issue it when it |
| 2993 |
starts to synthesize the message or when it receives the message. |
| 2994 |
|
| 2995 |
It is prepended by the code @code{701} and takes the form |
| 2996 |
|
| 2997 |
@example |
| 2998 |
701 BEGIN |
| 2999 |
@end example |
| 3000 |
|
| 3001 |
@item END |
| 3002 |
|
| 3003 |
This event must be issued whenever the module terminates speaking the |
| 3004 |
given message because it reached its end. If this is not possible, it |
| 3005 |
can issue this event when it is ready to receive a new message after |
| 3006 |
speaking the previous message. |
| 3007 |
|
| 3008 |
Each @code{END} must always be preceded (possibly not directly) by a |
| 3009 |
@code{BEGIN}. |
| 3010 |
|
| 3011 |
It is prepended by the code @code{702} and takes the form |
| 3012 |
|
| 3013 |
@example |
| 3014 |
702 END |
| 3015 |
@end example |
| 3016 |
|
| 3017 |
@item STOP |
| 3018 |
|
| 3019 |
This event should be issued whenever the module terminates speaking |
| 3020 |
the given message without reaching its end (as a consequence of |
| 3021 |
receiving the STOP command or because of some error) not because of |
| 3022 |
a @code{PAUSE} command. When the synthesizer in use doesn't allow |
| 3023 |
the module to decide, the event @code{END} can be used instead. |
| 3024 |
|
| 3025 |
Each @code{STOP} must always be preceded (possibly not directly) by a |
| 3026 |
@code{BEGIN}. |
| 3027 |
|
| 3028 |
It is prepended by the code @code{703} and takes the form |
| 3029 |
|
| 3030 |
@example |
| 3031 |
703 STOP |
| 3032 |
@end example |
| 3033 |
|
| 3034 |
@item PAUSE |
| 3035 |
|
| 3036 |
This event should be issued whenever the module terminates speaking |
| 3037 |
the given message without reaching its end because of receiving the |
| 3038 |
@code{PAUSE} command. |
| 3039 |
|
| 3040 |
Each @code{PAUSE} must always be preceded (possibly not directly) by a |
| 3041 |
@code{BEGIN}. |
| 3042 |
|
| 3043 |
It is prepended by the code @code{704} and takes the form |
| 3044 |
|
| 3045 |
@example |
| 3046 |
704 PAUSE |
| 3047 |
@end example |
| 3048 |
|
| 3049 |
@item INDEX MARK |
| 3050 |
|
| 3051 |
This event should be issued by the output module (if supported) |
| 3052 |
whenever an index mark (SSML tag @code{<mark/>}) is passed while speaking |
| 3053 |
a message. It is preceded by the code @code{700} and takes the form |
| 3054 |
|
| 3055 |
@example |
| 3056 |
700-name |
| 3057 |
700 INDEX MARK |
| 3058 |
@end example |
| 3059 |
|
| 3060 |
where @code{name} is the value of the SSML attribute @code{name} in |
| 3061 |
the tag @code{<mark/>}. |
| 3062 |
|
| 3063 |
@item AUDIO |
| 3064 |
|
| 3065 |
This event should be issued by the output module to produce audio through the |
| 3066 |
server. It is preceded by the code @code{705} and takes the form |
| 3067 |
|
| 3068 |
@example |
| 3069 |
705-bits=16 |
| 3070 |
705-num_channels=1 |
| 3071 |
705-sample_rate=16000 |
| 3072 |
705-num_samples=1234 |
| 3073 |
705-AUDIO\0data... |
| 3074 |
705 AUDIO |
| 3075 |
@end example |
| 3076 |
|
| 3077 |
The first lines provide the exact encoding of the data being passed. |
| 3078 |
|
| 3079 |
To avoid confusion with the @code{\n} character, an HDLC encoding is used, with |
| 3080 |
the @code{0x7D} escape character: whenever @code{\n} or @code{0x7D} appears in |
| 3081 |
the data, its 5th bit is inverted and it is prefixed with @code{0x7D}. |
| 3082 |
|
| 3083 |
@item ICON |
| 3084 |
|
| 3085 |
This event should be issued by the output module to emit a sound icon through |
| 3086 |
the server. It is preceded by the code @code{706} and takes the form |
| 3087 |
|
| 3088 |
@example |
| 3089 |
706-name |
| 3090 |
706 ICON |
| 3091 |
@end example |
| 3092 |
|
| 3093 |
where @code{name} is the sound icon name. |
| 3094 |
|
| 3095 |
@end table |
| 3096 |
|
| 3097 |
@node How to Write New Output Module, The Skeleton of an Output Module, Communication Protocol for Output Modules, Output Modules |
| 3098 |
@subsection How to Write New Output Module |
| 3099 |
|
| 3100 |
If you want to write your own output module, there are basically three |
| 3101 |
ways to do it. |
| 3102 |
|
| 3103 |
Either you can program it all yourself, which is fine as long as you stick to |
| 3104 |
the definition of an output module and its communication protocol. |
| 3105 |
|
| 3106 |
You can also use our @file{libspeechd_module} library, which deals with the |
| 3107 |
communication protocol and other formal things that are common for all modules. |
| 3108 |
It is provided under a BSD license and thus allows to integrate it along |
| 3109 |
proprietary software. You will have to provide a series of functions, an example |
| 3110 |
is provided in @code{src/modules/skeleton0.c}, which can freely serve as a basic |
| 3111 |
for your module. You can also read @code{src/modules/skeleton0_espeak-ng*.c}, |
| 3112 |
which show the various ways to plug a synthesizer, depending whether the |
| 3113 |
synthesizer works in synchronous mode (@code{-sync} variants) or asynchronously |
| 3114 |
in a separate thread (@code{-async} variants), and whether the synthesizer emits |
| 3115 |
audio itself or can produce wave files to be sent to the server (@code{-server} |
| 3116 |
variants). |
| 3117 |
|
| 3118 |
The nicest way, recommended for all modules shipped along speech-dispatcher, is |
| 3119 |
to make use of all of our our @file{module_*.c} tools. This will handle for you |
| 3120 |
all configuration file parsing, option setting etc. Here is how you can do it |
| 3121 |
using the provided tools. |
| 3122 |
|
| 3123 |
We will recommend here a basic structure of the code for an output |
| 3124 |
module you should follow, although it's perfectly ok to establish your |
| 3125 |
own if you have reasons to do so, if all the necessary functions and |
| 3126 |
data are defined somewhere in the file. For this purpose, we will use |
| 3127 |
examples from the output module for Flite (Festival Lite), so it's |
| 3128 |
recommended to keep looking at @code{flite.c} for reference. |
| 3129 |
|
| 3130 |
A few rules you should respect: |
| 3131 |
@itemize |
| 3132 |
@item |
| 3133 |
The @file{module_*.c} files should be included at the specified place and |
| 3134 |
in the specified order, because they include directly some pieces of the |
| 3135 |
code and won't work in other places. |
| 3136 |
@item |
| 3137 |
If one or more new threads are used in the output module, they must block all signals. |
| 3138 |
@item |
| 3139 |
On module_close(), all lateral threads and processes should be terminated, |
| 3140 |
all memory freed. Don't assume module_close() is always called before exit() |
| 3141 |
and the sources will be freed automatically. |
| 3142 |
@item |
| 3143 |
We will be happy if all the copyrights are assigned to Brailcom, o.p.s. |
| 3144 |
in order for us to be in a better legal position against possible intruders. |
| 3145 |
@end itemize |
| 3146 |
|
| 3147 |
@node The Skeleton of a Bare Output Module |
| 3148 |
@subsection The Skeleton of a Bare Output Module |
| 3149 |
|
| 3150 |
If you go for the BSD-provided skeleton way, you can start |
| 3151 |
with @code{skeleton0.c}. Add the synthesis initialization call |
| 3152 |
with default parameters to @code{module_init}, the synchronous |
| 3153 |
synthesizing call to @code{module_speak_sync}, and the synthesis |
| 3154 |
shutdown call to @code{module_close}. Link this with |
| 3155 |
@file{libspeechd_module}. Install this along other modules, and create an empty |
| 3156 |
configuration file for it. This should already provide you with a working |
| 3157 |
module, though with very limited support. |
| 3158 |
|
| 3159 |
The next step would be to add support for selecting the voice. Fix |
| 3160 |
@code{module_list_voices} to return a proper list of voices. In |
| 3161 |
@code{module_set}, when @code{var} is @code{voice}, @code{synthesis_voice}, or |
| 3162 |
@code{language}, select a voice according to @code{val}. |
| 3163 |
|
| 3164 |
This stage of development is examplified in @file{src/modules/skeleton0_espeak-ng-sync.c}. |
| 3165 |
|
| 3166 |
The following testcase examples should then be working: |
| 3167 |
|
| 3168 |
@example |
| 3169 |
# lists all voices |
| 3170 |
spd-say -o $mymodule -L |
| 3171 |
|
| 3172 |
spd-say -w -o $mymodule -l en-US Hello |
| 3173 |
# Should pronounce Bonjour in french |
| 3174 |
spd-say -w -o $mymodule -l fr-FR Bonjour |
| 3175 |
|
| 3176 |
spd-say -w -o $mymodule -l en-US Hello |
| 3177 |
# Should pronounce Bonjour with the specified french voice, as named in the -L output |
| 3178 |
spd-say -w -o $mymodule -y "$afrenchvoice" Bonjour |
| 3179 |
|
| 3180 |
spd-say -w -o $mymodule -l en-US Hello |
| 3181 |
# Should pronounce Bonjour in french with the specified french voice |
| 3182 |
spd-say -w -o $mymodule -l fr-FR -y "$afrenchvoice" Bonjour |
| 3183 |
|
| 3184 |
spd-say -w -o $mymodule -l en-US Hello |
| 3185 |
# Should pronounce Bonjour in french with a female voice (if available) |
| 3186 |
spd-say -w -o $mymodule -l fr-FR -t female1 Bonjour |
| 3187 |
|
| 3188 |
spd-say -w -o $mymodule -l en-US Hello |
| 3189 |
# Should pronounce Bonjour in french with a different female voice (if available) |
| 3190 |
spd-say -w -o $mymodule -l fr-FR -t female2 Bonjour |
| 3191 |
|
| 3192 |
spd-say -w -o $mymodule -l en-US Hello |
| 3193 |
# Should pronounce Bonjour in french even we passed a bogus voice name |
| 3194 |
spd-say -w -o $mymodule -l fr-FR -y bleaaaarg Bonjour |
| 3195 |
@end example |
| 3196 |
|
| 3197 |
A most useful next step is to support stopping the synthesis. This can be |
| 3198 |
supported two ways. Either the synthesis can call a callback from times to |
| 3199 |
times, in which case you can call @code{module_process(STDIN_FILE, 0)} to poll |
| 3200 |
for messages from the server. Or the synthesis can run asynchronously in a |
| 3201 |
separate thread, in which case you need to use |
| 3202 |
@code{module_speak} instead of @code{module_speak_sync}: it should return |
| 3203 |
immediately after starting the production of synthesis. Then |
| 3204 |
@code{module_speak_begin()} should be called when it actually |
| 3205 |
starts emitting audio, and @code{module_speak_end()} should be called when it is |
| 3206 |
finished emitting audio. In either cases, if @code{module_stop} |
| 3207 |
is getting called, the synthesis should stop as soon as possible and |
| 3208 |
@code{module_speak_stop()} be called instead of @code{module_speak_end()}. |
| 3209 |
Similarly, if @code{module_pause} is getting called, the synthesis should stop |
| 3210 |
on next mark whose name starts with @code{__spd_}, and |
| 3211 |
@code{module_speak_pause()} be called instead of @code{module_speak_end()}. |
| 3212 |
As a first step, @code{module_pause} can be made to behave just like |
| 3213 |
@code{module_stop}. |
| 3214 |
|
| 3215 |
This asynchronous support is examplified in |
| 3216 |
@file{src/modules/skeleton0_espeak-ng-async.c}. It is already quite nice for a lot of |
| 3217 |
use cases: the user is now able to interrupt the synthesis e.g. through a screen |
| 3218 |
reader action. |
| 3219 |
|
| 3220 |
It is then useful to make @code{module_set} recognize other useful |
| 3221 |
voice parameters to improve the synthesis: @code{rate}, @code{pitch}, |
| 3222 |
@code{pitch_range}, @code{volume}, @code{punctuation_mode}, |
| 3223 |
@code{spelling_mode}, @code{cap_let_recogn}. |
| 3224 |
|
| 3225 |
If the synthesis permits it, it is better to support server-side audio |
| 3226 |
rendering: instead of playing audio itself, the synthesis should provide pieces |
| 3227 |
of wave files, to be sent to the server with @code{module_tts_output_server}. |
| 3228 |
Examples are available in @code{src/modules/skeleton0_espeak-ng-async-server.c} |
| 3229 |
and @code{src/modules/skeleton0_espeak-ng-sync-server.c}. The |
| 3230 |
@code{module_audio_set} function should in that case recognize only the |
| 3231 |
@code{server} audio method. |
| 3232 |
|
| 3233 |
If the synthesis does not permit server-side audio rendering, optionally |
| 3234 |
@code{module_audio_set} can be made to recognize precise audio settings to be |
| 3235 |
used by the synthesis-side audio rendering. |
| 3236 |
|
| 3237 |
For easier debugging, @code{module_loglevel_set} and @code{module_debug} can be |
| 3238 |
implemented. |
| 3239 |
|
| 3240 |
A useful step is probably to add support for the configuration file, by making |
| 3241 |
@code{module_config} parse the configuration file and set synthesis parameters |
| 3242 |
accordingly. |
| 3243 |
|
| 3244 |
@node The Skeleton of an Output Module, Output Module Functions, How to Write New Output Module, Output Modules |
| 3245 |
@subsection The Skeleton of an Output Module |
| 3246 |
|
| 3247 |
The previous section documented how to write an output module in general. In this |
| 3248 |
section, we document the preferred way for writing modules to be shipped with |
| 3249 |
speech-dispatcher. |
| 3250 |
|
| 3251 |
Each output module should include @file{module_utils.h} where the |
| 3252 |
SPDMsgSettings structure is defined to be able to handle the different |
| 3253 |
speech synthesis settings. This file also provides tools which help |
| 3254 |
with writing output modules and making the code simpler. |
| 3255 |
|
| 3256 |
@example |
| 3257 |
#include "module_utils.h" |
| 3258 |
@end example |
| 3259 |
|
| 3260 |
If your plugin needs the audio tools (if you take |
| 3261 |
care of the output to the soundcard instead of the synthesizer), |
| 3262 |
you also have to include @file{spd_audio.h} |
| 3263 |
|
| 3264 |
@example |
| 3265 |
#include "spd_audio.h" |
| 3266 |
@end example |
| 3267 |
|
| 3268 |
The definition of macros @code{MODULE_NAME} and @code{MODULE_VERSION} |
| 3269 |
should follow: |
| 3270 |
|
| 3271 |
@example |
| 3272 |
#define MODULE_NAME "flite" |
| 3273 |
#define MODULE_VERSION "0.1" |
| 3274 |
@end example |
| 3275 |
|
| 3276 |
If you want to use the @code{DBG(message)} macro from @file{module_utils.c} |
| 3277 |
to print out debugging messages, you should insert these two lines. (Please |
| 3278 |
don't use printf for debugging, this doesn't work with multiple processes!) |
| 3279 |
(You will later have to actually start debugging in @code{module_init()}) |
| 3280 |
|
| 3281 |
@example |
| 3282 |
DECLARE_DEBUG(); |
| 3283 |
@end example |
| 3284 |
|
| 3285 |
You don't have to define the prototypes of the core functions |
| 3286 |
like module_speak() and module_stop(), these are already |
| 3287 |
defined in @file{module_utils.h} |
| 3288 |
|
| 3289 |
Optionally, if your output module requires some special configuration, |
| 3290 |
apart from defining voices and configuring debugging (they are handled |
| 3291 |
differently, see below), you can declare the requested option |
| 3292 |
here. It will expand into a dotconf callback and declaration of the |
| 3293 |
variable. |
| 3294 |
|
| 3295 |
(You will later have to actually register these options for |
| 3296 |
Speech Dispatcher in @code{module_load()}) |
| 3297 |
|
| 3298 |
There are currently 4 types of possible configuration options: |
| 3299 |
|
| 3300 |
@itemize |
| 3301 |
@item @code{MOD_OPTION_1_INT(name); /* Set up `int name' */} |
| 3302 |
@item @code{MOD_OPTION_1_STR(name); /* Set up `char* name' */} |
| 3303 |
@item @code{MOD_OPTION_2(name); /* Set up `char *name[2]' */} |
| 3304 |
@item @code{MOD_OPTION_@{2,3@}_HT(name); /* Set up a hash table */} |
| 3305 |
@end itemize |
| 3306 |
|
| 3307 |
@xref{Output Modules Configuration}. |
| 3308 |
|
| 3309 |
For example Flite uses 2 options: |
| 3310 |
@example |
| 3311 |
MOD_OPTION_1_INT(FliteMaxChunkLength); |
| 3312 |
MOD_OPTION_1_STR(FliteDelimiters); |
| 3313 |
@end example |
| 3314 |
|
| 3315 |
Every output module is started in 2 phases: @emph{loading} and |
| 3316 |
@emph{initialization}. |
| 3317 |
|
| 3318 |
The goal of loading is to initialize empty structures for storing |
| 3319 |
settings and declare the DotConf callbacks for parsing configuration |
| 3320 |
files. In the second phase, initialization, all the configuration has |
| 3321 |
been read and the output module can accomplish the rest (check if |
| 3322 |
the synthesizer works, set up threads etc.). |
| 3323 |
|
| 3324 |
You should start with the definition of @code{module_load()}. |
| 3325 |
|
| 3326 |
@example |
| 3327 |
int |
| 3328 |
module_load(void) |
| 3329 |
@{ |
| 3330 |
@end example |
| 3331 |
|
| 3332 |
Then you should initialize the settings tables. These are defined in |
| 3333 |
@file{module_utils.h} and will be used to store the settings received |
| 3334 |
by the @code{SET} command. |
| 3335 |
@example |
| 3336 |
INIT_SETTINGS_TABLES(); |
| 3337 |
@end example |
| 3338 |
|
| 3339 |
Also, define the configuration callbacks for debugging if you use |
| 3340 |
the @code{DBG()} macro. |
| 3341 |
|
| 3342 |
@example |
| 3343 |
REGISTER_DEBUG(); |
| 3344 |
@end example |
| 3345 |
|
| 3346 |
Now you can finally register the options for the configuration file |
| 3347 |
parsing. Just use these macros: |
| 3348 |
@itemize |
| 3349 |
@item MOD_OPTION_1_INT_REG(name, default); /* for integer parameters */ |
| 3350 |
@item MOD_OPTION_1_STR_REG(name, default); /* for string parameters */ |
| 3351 |
@item MOD_OPTION_MORE_REG(name); /* for an array of strings */ |
| 3352 |
@item MOD_OPTION_HT_REG(name); /* for hash tables */ |
| 3353 |
@end itemize |
| 3354 |
|
| 3355 |
Again, an example from Flite: |
| 3356 |
@example |
| 3357 |
MOD_OPTION_1_INT_REG(FliteMaxChunkLength, 300); |
| 3358 |
MOD_OPTION_1_STR_REG(FliteDelimiters, "."); |
| 3359 |
@end example |
| 3360 |
|
| 3361 |
If you want to enable the mechanism for setting |
| 3362 |
voices through AddVoice, use this function (for |
| 3363 |
an example see @code{generic.c}): |
| 3364 |
|
| 3365 |
Example from Festival: |
| 3366 |
@example |
| 3367 |
module_register_settings_voices(); |
| 3368 |
@end example |
| 3369 |
|
| 3370 |
@xref{Output Modules Configuration}. |
| 3371 |
|
| 3372 |
If everything went correctly, the function should return 0, otherwise -1. |
| 3373 |
|
| 3374 |
@example |
| 3375 |
return 0; |
| 3376 |
@} |
| 3377 |
@end example |
| 3378 |
|
| 3379 |
The second phase of starting an output module is handled by: |
| 3380 |
|
| 3381 |
@example |
| 3382 |
int |
| 3383 |
module_init(void) |
| 3384 |
@{ |
| 3385 |
@end example |
| 3386 |
|
| 3387 |
If you use the DBG() macro, you should init debugging on the start |
| 3388 |
of this function. From that moment on, you can use DBG(). Apart from that, |
| 3389 |
the body of this function is entirely up to you. You should do all the |
| 3390 |
necessary initialization of the particular synthesizer. All declared |
| 3391 |
configuration variables and configuration hash tables, together with |
| 3392 |
the definition of voices, are filled with their values (either default |
| 3393 |
or read from configuration), so you can use them already. |
| 3394 |
|
| 3395 |
@example |
| 3396 |
INIT_DEBUG(); |
| 3397 |
DBG("FliteMaxChunkLength = %d\n", FliteMaxChunkLength); |
| 3398 |
DBG("FliteDelimiters = %s\n", FliteDelimiters); |
| 3399 |
@end example |
| 3400 |
|
| 3401 |
This function should return 0 if the module was initialized |
| 3402 |
successfully, or -1 if some failure was encountered. In this case, you |
| 3403 |
should clean up everything, cancel threads, deallocate memory etc.; no |
| 3404 |
more functions of this output module will be touched (except for other |
| 3405 |
tries to load and initialize the module). |
| 3406 |
|
| 3407 |
It is very important that @code{module_init} tries to check that the synthesis |
| 3408 |
works as much as possible. Otherwise, if users switch to this module and it does |
| 3409 |
not emit sound at all without reporting errors, blind users will have no audio |
| 3410 |
feedback to be able to switch back to a working module. |
| 3411 |
|
| 3412 |
Example from Flite: |
| 3413 |
|
| 3414 |
@example |
| 3415 |
/* Init flite and register a new voice */ |
| 3416 |
flite_init(); |
| 3417 |
flite_voice = register_cmu_us_kal(); |
| 3418 |
|
| 3419 |
if (flite_voice == NULL)@{ |
| 3420 |
DBG("Couldn't register the basic kal voice.\n"); |
| 3421 |
return -1; |
| 3422 |
@} |
| 3423 |
[...] |
| 3424 |
@end example |
| 3425 |
|
| 3426 |
The third part is opening the audio. This is commanded |
| 3427 |
by the @code{AUDIO} protocol command. If the synthesizer is able |
| 3428 |
to retrieve audio data, it is desirable to open the @code{spd_audio} |
| 3429 |
output according to the requested parameters and then use this |
| 3430 |
method for audio output. Audio initialization can be done as |
| 3431 |
follows: |
| 3432 |
|
| 3433 |
@example |
| 3434 |
int |
| 3435 |
module_audio_init(char **status_info)@{ |
| 3436 |
DBG("Opening audio"); |
| 3437 |
return module_audio_init_spd(status_info); |
| 3438 |
@} |
| 3439 |
@end example |
| 3440 |
|
| 3441 |
If it is impossible to retrieve audio from the synthesizer and |
| 3442 |
the synthesizer itself is used for playback, than the module must |
| 3443 |
still contain this function, but it should just return 0 and |
| 3444 |
do nothing. |
| 3445 |
|
| 3446 |
Now you have to define all the synthesis control functions |
| 3447 |
@code{module_speak}, @code{module_stop} etc. See @ref{Output Module |
| 3448 |
Functions}. |
| 3449 |
|
| 3450 |
At the end, this simple include provides the main() function and all |
| 3451 |
the functionality related to being an output module of Speech |
| 3452 |
Dispatcher (parsing argv[] parameters, communicating on stdin/stdout, |
| 3453 |
...). It's recommended to study this file carefully and try to |
| 3454 |
understand what exactly it does, as it will be part of the source code |
| 3455 |
of your output module. |
| 3456 |
|
| 3457 |
@example |
| 3458 |
#include "module_main.c" |
| 3459 |
@end example |
| 3460 |
|
| 3461 |
If it doesn't work, it's most likely not your fault. Complain! This |
| 3462 |
manual is not complete and the instructions in this sections aren't |
| 3463 |
either. Get in touch with us and together we can figure out what's |
| 3464 |
wrong, fix it and then warn others in this manual. |
| 3465 |
|
| 3466 |
@node Output Module Functions, Module Utils Functions and Macros, The Skeleton of an Output Module, Output Modules |
| 3467 |
@subsection Output Module Functions |
| 3468 |
|
| 3469 |
@deffn {Output Module Functions} void module_speak_sync (char *data, size_t bytes, EMessageType msgtype) |
| 3470 |
@findex module_speak() |
| 3471 |
|
| 3472 |
This is the function where the actual speech output is produced. It is |
| 3473 |
called every time Speech Dispatcher decides to send a message to |
| 3474 |
synthesis. The data of length @var{bytes} are passed in |
| 3475 |
a NULL terminated string @var{data}. The argument @var{msgtype} |
| 3476 |
defines what type of message it is (different types should be handled |
| 3477 |
differently, if the synthesizer supports it). |
| 3478 |
|
| 3479 |
Each output module should take care of setting the output device to |
| 3480 |
the parameters from msg_settings (defined in module_utils.h) (See |
| 3481 |
SPDMsgSettings in @file{module_utils.h}). However, it is not an error if |
| 3482 |
some of these values are ignored. At least rate, pitch and language |
| 3483 |
should be set correctly. |
| 3484 |
|
| 3485 |
Speed and pitch are values between -100 and 100 included. 0 is the default |
| 3486 |
value that represents normal speech flow. So -100 is the slowest (or lowest) |
| 3487 |
and +100 is the fastest (or highest) speech. |
| 3488 |
|
| 3489 |
The language parameter is given as a null-terminated string containing |
| 3490 |
the name of the language according to RFC 1766 (en, cs, fr, en-US, ...). If the |
| 3491 |
requested language is not supported by this synthesizer, it's ok to abort |
| 3492 |
and return 0, because that's an error in user settings. |
| 3493 |
|
| 3494 |
An easy way to set the parameters is using the UPDATE_PARAMETER() and |
| 3495 |
UPDATE_STRING_PARAMETER() macros. @xref{Module Utils Functions and |
| 3496 |
Macros}. |
| 3497 |
|
| 3498 |
Example from festival: |
| 3499 |
@example |
| 3500 |
UPDATE_STRING_PARAMETER(language, festival_set_language); |
| 3501 |
UPDATE_PARAMETER(voice, festival_set_voice); |
| 3502 |
UPDATE_PARAMETER(rate, festival_set_rate); |
| 3503 |
UPDATE_PARAMETER(pitch, festival_set_pitch); |
| 3504 |
UPDATE_PARAMETER(punctuation_mode, festival_set_punctuation_mode); |
| 3505 |
UPDATE_PARAMETER(cap_let_recogn, festival_set_cap_let_recogn); |
| 3506 |
@end example |
| 3507 |
|
| 3508 |
Once this function has checked that everything is OK, it must call |
| 3509 |
@code{module_speak_ok()} to let the server know that the speak was |
| 3510 |
accepted. From then on, the server may send stop requests, so resetting the stop |
| 3511 |
state must be done before calling this. |
| 3512 |
On errors, @code{module_speak_error()} has to be called instead. |
| 3513 |
|
| 3514 |
When actual synthesis starts, @code{module_speak_begin()} must be called to let |
| 3515 |
the server know of this. On synthesis termination, @code{module_speak_end()} |
| 3516 |
should be called (or @code{module_speak_pause()}, @code{module_speak_stopped()} |
| 3517 |
if the synthesis was interrupted through @code{module_pause()} or @code{module_stop()}). |
| 3518 |
|
| 3519 |
This function should return only when it is finished with synthesizing. It |
| 3520 |
should however call @code{module_process(STDIN_FILENO, 0)} periodically so as |
| 3521 |
to promptly process messages coming from the server, notably speech stopping |
| 3522 |
requests. |
| 3523 |
@end deffn |
| 3524 |
|
| 3525 |
@deffn {Output Module Functions} int module_speak (char *data, size_t bytes, EMessageType msgtype) |
| 3526 |
@findex module_speak() |
| 3527 |
|
| 3528 |
This is the same as @code{module_speak_sync}, except that it proceeds |
| 3529 |
asynchronously, it can be used when the synthesis works asynchronously. |
| 3530 |
|
| 3531 |
Instead of calling @code{module_speak_ok()} or @code{module_speak_error()}, |
| 3532 |
this function should return 0 if it fails and 1 if the delivery |
| 3533 |
to the synthesizer is successful. It should return immediately, |
| 3534 |
because otherwise, it would block stopping, priority handling |
| 3535 |
and other important things in Speech Dispatcher. |
| 3536 |
|
| 3537 |
If there is a need to stay longer, it can call |
| 3538 |
@code{module_process(STDIN_FILENO, 0)} to process messages coming from the |
| 3539 |
server, but in that case @code{module_speak_sync} could as well be used. |
| 3540 |
|
| 3541 |
Note: if the synthesis creates separate threads, you have to set |
| 3542 |
them to ignore all signals. The simplest way to do this is to use |
| 3543 |
@code{spd_pthread_create()} (which is defined in |
| 3544 |
module_utils.c) instead of @code{pthread_create()}. |
| 3545 |
@end deffn |
| 3546 |
|
| 3547 |
@deffn {Output module function} {int module_stop} (void) |
| 3548 |
@findex module_stop() |
| 3549 |
|
| 3550 |
This function should stop the synthesis of the currently spoken message |
| 3551 |
immediately and throw away the rest of the message. |
| 3552 |
|
| 3553 |
This function should return immediately. Speech Dispatcher will |
| 3554 |
not send another command until module_report_event_stop() is called. |
| 3555 |
Note that you cannot call module_report_event_stop() from within |
| 3556 |
the call to module_stop(). The best thing to do is emit |
| 3557 |
the stop event from another thread. |
| 3558 |
|
| 3559 |
It should return 0 on success, -1 otherwise. |
| 3560 |
@end deffn |
| 3561 |
|
| 3562 |
@deffn {Output module function} {size_t module_pause} (void) |
| 3563 |
@findex module_pause() |
| 3564 |
|
| 3565 |
This function should stop speaking on the synthesizer (or sending |
| 3566 |
data to soundcard) just after sending an @code{__spd_} index |
| 3567 |
mark so that Speech Dispatcher knows the position of stop. |
| 3568 |
|
| 3569 |
The pause can wait for a short time until |
| 3570 |
such index mark is reached. However, if it's not possible to determine |
| 3571 |
the exact position, this function should have the same effect |
| 3572 |
as @code{module_stop}. |
| 3573 |
|
| 3574 |
This function should return immediately. Speech Dispatcher will |
| 3575 |
not send another command until module_report_event_pause() is called. |
| 3576 |
Note that you cannot call module_report_event_pause() from within |
| 3577 |
the call to module_pause(). The best thing to do is emit |
| 3578 |
the pause event from another thread. |
| 3579 |
|
| 3580 |
For some software synthesizers, the desired effect can be archieved in this way: |
| 3581 |
When @code{module_speak()} is called, you execute a separate |
| 3582 |
process and pass it the requested message. This process |
| 3583 |
cuts the message into sentences and then runs in a loop |
| 3584 |
and sends the pieces to synthesis. If a signal arrives |
| 3585 |
from @code{module_pause()}, you set a flag and stop the loop |
| 3586 |
at the point where next piece of text would be synthesized. |
| 3587 |
|
| 3588 |
It's not an error if this function is called when the device |
| 3589 |
is not speaking. In this case, it should return 0. |
| 3590 |
|
| 3591 |
Note there is no module_resume() function. The semantics of |
| 3592 |
@code{module_pause()} is the same as @code{module_stop()} except that |
| 3593 |
your module should stop after reaching a @code{__spd_} index mark. |
| 3594 |
Just like @code{module_stop()}, it should discard the rest of the |
| 3595 |
message after pausing. On the next @code{module_speak()} call, |
| 3596 |
Speech Dispatcher will resend the rest of the message after the |
| 3597 |
index mark. |
| 3598 |
@end deffn |
| 3599 |
|
| 3600 |
|
| 3601 |
@node Module Utils Functions and Macros, Index Marks in Output Modules, Output Module Functions, Output Modules |
| 3602 |
@subsection Module Utils Functions and Macros |
| 3603 |
|
| 3604 |
This section describes the various variables, functions and macros |
| 3605 |
that are available in the @file{module_utils.h} file. They are |
| 3606 |
intended to make writing new output modules easier and allow the |
| 3607 |
programmer to reuse existing pieces of code instead of writing |
| 3608 |
everything from scratch. |
| 3609 |
|
| 3610 |
@menu |
| 3611 |
* Initialization Macros and Functions:: |
| 3612 |
* Generic Macros and Functions:: |
| 3613 |
* Functions used by module_main.c:: |
| 3614 |
* Functions for use when talking to synthesizer:: |
| 3615 |
* Multi-process output modules:: |
| 3616 |
* Memory Handling Functions:: |
| 3617 |
@end menu |
| 3618 |
|
| 3619 |
@node Initialization Macros and Functions, Generic Macros and Functions, Module Utils Functions and Macros, Module Utils Functions and Macros |
| 3620 |
@subsubsection Initialization Macros and Functions |
| 3621 |
|
| 3622 |
@deffn {Module Utils macro} INIT_SETTINGS_TABLES () |
| 3623 |
@findex INIT_SETTINGS_TABLES |
| 3624 |
This macro initializes the settings tables where the parameters |
| 3625 |
received with the @code{SET} command are stored. You must call |
| 3626 |
this macro if you want to use the @code{UPDATE_PARAMETER()} |
| 3627 |
and @code{UPDATE_STRING_PARAMETER()} macros. |
| 3628 |
|
| 3629 |
It is intended to be called from inside a function just |
| 3630 |
after the output module starts. |
| 3631 |
@end deffn |
| 3632 |
|
| 3633 |
@subsubsection Debugging Macros |
| 3634 |
@deffn {Module Utils macro} DBG (format, ...) |
| 3635 |
@findex DBG |
| 3636 |
DBG() outputs a debugging message, if the @code{Debug} option in module's |
| 3637 |
configuration is set, to the file specified in configuration ad |
| 3638 |
@code{DebugFile}. The parameter syntax is the same as for the printf() |
| 3639 |
function. In fact, it calls printf() internally. |
| 3640 |
@end deffn |
| 3641 |
|
| 3642 |
@deffn {Module Utils macro} FATAL (text) |
| 3643 |
@findex FATAL |
| 3644 |
Outputs a message specified as @code{text} and calls exit() with |
| 3645 |
the value EXIT_FAILURE. This terminates the whole output module |
| 3646 |
without trying to kill the child processes or freeing other |
| 3647 |
resources other than those that will be freed by the system. |
| 3648 |
|
| 3649 |
It is intended to be used after some severe error has occurred. |
| 3650 |
@end deffn |
| 3651 |
|
| 3652 |
@node Generic Macros and Functions, Functions used by module_main.c, Initialization Macros and Functions, Module Utils Functions and Macros |
| 3653 |
@subsubsection Generic Macros and Functions |
| 3654 |
|
| 3655 |
@deffn {Module Utils macro} UPDATE_PARAMETER (param, setter) |
| 3656 |
@findex UPDATE_PARAMETER |
| 3657 |
Tests if the integer or enum parameter specified in @code{param} |
| 3658 |
(e.g. rate, pitch, cap_let_recogn, ...) changed since the |
| 3659 |
last time when the @code{setter} function was called. |
| 3660 |
|
| 3661 |
If it changed, it calls the function @code{setter} with the |
| 3662 |
new value. (The new value is stored in the msg_settings |
| 3663 |
structure that is created by module_utils.h, which |
| 3664 |
you normally don't have to care about.) |
| 3665 |
|
| 3666 |
The function @code{setter} should be defined as: |
| 3667 |
@example |
| 3668 |
void setter_name(type value); |
| 3669 |
@end example |
| 3670 |
|
| 3671 |
Please look at the @code{SET} command in the communication protocol |
| 3672 |
for the list of all available parameters. |
| 3673 |
@pxref{Communication Protocol for Output Modules}. |
| 3674 |
|
| 3675 |
An example from Festival output module: |
| 3676 |
@verbatim |
| 3677 |
static void |
| 3678 |
festival_set_rate(signed int rate) |
| 3679 |
{ |
| 3680 |
assert(rate >= -100 && rate <= +100); |
| 3681 |
festivalSetRate(festival_info, rate); |
| 3682 |
} |
| 3683 |
[...] |
| 3684 |
int |
| 3685 |
module_speak(char *data, size_t bytes, EMessageType msgtype) |
| 3686 |
{ |
| 3687 |
[...] |
| 3688 |
UPDATE_PARAMETER(rate, festival_set_rate); |
| 3689 |
UPDATE_PARAMETER(pitch, festival_set_pitch); |
| 3690 |
[...] |
| 3691 |
} |
| 3692 |
@end verbatim |
| 3693 |
@end deffn |
| 3694 |
|
| 3695 |
@deffn {Module Utils macro} UPDATE_STRING_PARAMETER (param, setter) |
| 3696 |
@findex UPDATE_STRING_PARAMETER |
| 3697 |
The same as @code{UPDATE_PARAMETER} except that it works for |
| 3698 |
parameters with a string value. |
| 3699 |
@end deffn |
| 3700 |
|
| 3701 |
@node Functions used by module_main.c, Functions for use when talking to synthesizer, Generic Macros and Functions, Module Utils Functions and Macros |
| 3702 |
@subsubsection Functions used by @file{module_main.c} |
| 3703 |
|
| 3704 |
@deffn {Module Utils function} char* do_speak(void) |
| 3705 |
@findex do_speak |
| 3706 |
Takes care of communication after the @code{SPEAK} command was |
| 3707 |
received. Calls @code{module_speak()} when the full text is received. |
| 3708 |
|
| 3709 |
It returns a response according to the communication protocol. |
| 3710 |
@end deffn |
| 3711 |
|
| 3712 |
@deffn {Module Utils function} char* do_stop(void) |
| 3713 |
@findex do_stop |
| 3714 |
Calls the @code{module_stop()} function of the particular |
| 3715 |
output module. |
| 3716 |
|
| 3717 |
It returns a response according to the communication protocol. |
| 3718 |
@end deffn |
| 3719 |
|
| 3720 |
@deffn {Module Utils function} char* do_pause(void) |
| 3721 |
@findex do_pause |
| 3722 |
Calls the @code{module_pause()} function of the particular |
| 3723 |
output module. |
| 3724 |
|
| 3725 |
It returns a response according to the communication protocol |
| 3726 |
and the value returned by @code{module_pause()}. |
| 3727 |
@end deffn |
| 3728 |
|
| 3729 |
@deffn {Module Utils function} char* do_set() |
| 3730 |
@findex do_set |
| 3731 |
Takes care of communication after the @code{SET} command was |
| 3732 |
received. Doesn't call any particular function of the output module, |
| 3733 |
only sets the values in the settings tables. (You should then call the |
| 3734 |
@code{UPDATE_PARAMETER()} macro in module_speak() to actually set the |
| 3735 |
synthesizer to these values.) |
| 3736 |
|
| 3737 |
It returns a response according to the communication protocol. |
| 3738 |
@end deffn |
| 3739 |
|
| 3740 |
@deffn {Module Utils function} char* do_speaking() |
| 3741 |
@findex do_speaking |
| 3742 |
Calls the @code{module_speaking()} function. |
| 3743 |
|
| 3744 |
It returns a response according to the communication protocol |
| 3745 |
and the value returned by @code{module_speaking()}. |
| 3746 |
@end deffn |
| 3747 |
|
| 3748 |
@deffn {Module Utils function} void do_quit() |
| 3749 |
@findex do_quit |
| 3750 |
Prints the farewell message to the standard output, according |
| 3751 |
to the protocol. Then it calls @code{module_close()}. |
| 3752 |
@end deffn |
| 3753 |
|
| 3754 |
@node Functions for use when talking to synthesizer, Multi-process output modules, Functions used by module_main.c, Module Utils Functions and Macros |
| 3755 |
@subsubsection Functions for use when talking to synthesizer |
| 3756 |
|
| 3757 |
@deffn {Module Utils function} static int module_get_message_part ( const char* message, char* part, unsigned int *pos, size_t maxlen, const char* dividers) |
| 3758 |
@findex module_get_message_part |
| 3759 |
|
| 3760 |
Gets a part of the @code{message} according to the specified @code{dividers}. |
| 3761 |
|
| 3762 |
It scans the text in @code{message} from the byte specified by |
| 3763 |
@code{*pos} and looks for one of the characters specified in |
| 3764 |
@code{dividers} followed by a whitespace character or the |
| 3765 |
terminating NULL byte. If one of them is encountered, the read text is |
| 3766 |
stored in @code{part} and the number of bytes read is |
| 3767 |
returned. If end of @code{message} is reached, the return value is |
| 3768 |
-1. |
| 3769 |
|
| 3770 |
@code{message} is the text to process. It must be a NULL-terminated |
| 3771 |
uni-byte string. |
| 3772 |
|
| 3773 |
@code{part} is a pointer to the place where the output text should |
| 3774 |
be stored. It must contain at least @code{maxlen} bytes of space. |
| 3775 |
|
| 3776 |
@code{maxlen} is the maximum number of bytes that should be written |
| 3777 |
to @code{part}. |
| 3778 |
|
| 3779 |
@code{dividers} is a NULL-terminated uni-byte string containing |
| 3780 |
the punctuation characters where the message should be divided |
| 3781 |
into smaller parts (if they are followed by whitespace). |
| 3782 |
|
| 3783 |
After returning, @code{pos} is the position |
| 3784 |
where the function terminated in processing @code{message}. |
| 3785 |
@end deffn |
| 3786 |
|
| 3787 |
@deffn {Output module function} void module_report_index_mark(char *mark) |
| 3788 |
@findex module_report_index_mark |
| 3789 |
@end deffn |
| 3790 |
@deffn {Output module function} void module_report_event_*() |
| 3791 |
@findex module_report_event_* |
| 3792 |
|
| 3793 |
The @code{module_report_} functions serve for reporting event |
| 3794 |
notifications and index marking events. You should use them whenever |
| 3795 |
you get an event from the synthesizer which is defined in the output |
| 3796 |
module communication protocol. |
| 3797 |
|
| 3798 |
Note that you cannot call these functions from within a call |
| 3799 |
to module_speak(), module_stop(), or module_pause(). The best |
| 3800 |
way to do this is to emit the events from another thread. |
| 3801 |
|
| 3802 |
@end deffn |
| 3803 |
|
| 3804 |
@deffn {Output module function} int module_close(void) |
| 3805 |
@findex module_close |
| 3806 |
|
| 3807 |
This function is called when Speech Dispatcher terminates. The output |
| 3808 |
module should terminate all threads and processes, free all resources, |
| 3809 |
close all sockets etc. Never assume this function is called only when |
| 3810 |
Speech Dispatcher terminates and exit(0) will do the work for you. It's |
| 3811 |
perfectly ok for Speech Dispatcher to load, unload or reload output modules |
| 3812 |
in the middle of its run. |
| 3813 |
|
| 3814 |
@end deffn |
| 3815 |
|
| 3816 |
@node Multi-process output modules, Memory Handling Functions, Functions for use when talking to synthesizer, Module Utils Functions and Macros |
| 3817 |
@subsubsection Multi-process output modules |
| 3818 |
|
| 3819 |
@deffn {Module Utils function} size_t module_parent_wfork ( TModuleDoublePipe dpipe, |
| 3820 |
const char* message, SPDMessageType msgtype, const size_t maxlen, |
| 3821 |
const char* dividers, int *pause_requested) |
| 3822 |
@findex module_parent_wfork |
| 3823 |
|
| 3824 |
It simply sends the data to the |
| 3825 |
child in smaller pieces and waits for confirmation with a single |
| 3826 |
@code{C} character on the pipe from child to parent. |
| 3827 |
|
| 3828 |
@code{dpipe} is a parameter which contains the information |
| 3829 |
necessary for communicating through pipes between the parent and the |
| 3830 |
child and vice-versa. |
| 3831 |
|
| 3832 |
@example |
| 3833 |
typedef struct@{ |
| 3834 |
int pc[2]; /* Parent to child pipe */ |
| 3835 |
int cp[2]; /* Child to parent pipe */ |
| 3836 |
@}TModuleDoublePipe; |
| 3837 |
@end example |
| 3838 |
|
| 3839 |
@code{message} is a pointer to a NULL-terminated string containing the message |
| 3840 |
for synthesis. |
| 3841 |
|
| 3842 |
@code{msgtype} is the type of the message for synthesis. |
| 3843 |
|
| 3844 |
@code{maxlen} is the maximum number of bytes that should be transferred |
| 3845 |
over the pipe. |
| 3846 |
|
| 3847 |
@code{dividers} is a NULL-terminated string containing the punctuation characters |
| 3848 |
at which this function should divide the message into smaller pieces. |
| 3849 |
|
| 3850 |
@code{pause_requested} is a pointer to an integer flag, which is either 0 if |
| 3851 |
no pause request is pending, or 1 if the function should terminate |
| 3852 |
at a convenient place in the message because a pause is requested. |
| 3853 |
|
| 3854 |
In the beginning, it initializes the pipes and then it enters a simple cycle: |
| 3855 |
@enumerate |
| 3856 |
@item |
| 3857 |
Reads a part of the message or an index mark using |
| 3858 |
@code{module_get_message_part()}. |
| 3859 |
@item |
| 3860 |
Looks if there isn't a pending request for pause and handles |
| 3861 |
it. |
| 3862 |
@item |
| 3863 |
Sends the current part of the message to the child |
| 3864 |
using @code{module_parent_dp_write()}. |
| 3865 |
@item |
| 3866 |
Waits until a single character @code{C} comes from the other pipe |
| 3867 |
using @code{module_parent_dp_read()}. |
| 3868 |
@item |
| 3869 |
Repeats the cycle or terminates, if there is no more data. |
| 3870 |
@end enumerate |
| 3871 |
@end deffn |
| 3872 |
|
| 3873 |
@deffn {Module Utils function} int module_parent_wait_continue(TModuleDoublePipe dpipe) |
| 3874 |
@findex module_parent_wait_continue |
| 3875 |
Waits until the character @code{C} (continue) is read from the pipe from child. |
| 3876 |
This function is intended to be run from the parent. |
| 3877 |
|
| 3878 |
@code{dpipe} is the double pipe used for communication between the child and parent. |
| 3879 |
|
| 3880 |
Returns 0 if the character was read or 1 if the pipe was broken before the |
| 3881 |
character could be read. |
| 3882 |
@end deffn |
| 3883 |
|
| 3884 |
@deffn {Module Utils function} void module_parent_dp_init (TModuleDoublePipe dpipe) |
| 3885 |
@findex module_parent_dp_init |
| 3886 |
Initializes pipes (dpipe) in the parent. Currently it only closes the unnecessary ends. |
| 3887 |
@end deffn |
| 3888 |
|
| 3889 |
@deffn {Module Utils function} void module_child_dp_close (TModuleDoublePipe dpipe) |
| 3890 |
@findex module_child_dp_init |
| 3891 |
Initializes pipes (dpipe) in the child. Currently it only closes the unnecessary ends. |
| 3892 |
@end deffn |
| 3893 |
|
| 3894 |
@deffn {Module Utils function} void module_child_dp_write(TModuleDoublePipe dpipe, const char *msg, size_t bytes) |
| 3895 |
@findex module_child_dp_write |
| 3896 |
Writes the specified number of @code{bytes} from @code{msg} to the pipe to the |
| 3897 |
parent. This function is intended, as the prefix says, to be run from the child. |
| 3898 |
Uses the pipes defined in @code{dpipe}. |
| 3899 |
@end deffn |
| 3900 |
|
| 3901 |
@deffn {Module Utils function} void module_parent_dp_write(TModuleDoublePipe dpipe, const char *msg, size_t bytes) |
| 3902 |
@findex module_parent_dp_write |
| 3903 |
Writes the specified number of @code{bytes} from @code{msg} into the pipe to the |
| 3904 |
child. This function is intended, as the prefix says, to be run from the parent. |
| 3905 |
Uses the pipes defined in @code{dpipe}. |
| 3906 |
@end deffn |
| 3907 |
|
| 3908 |
@deffn {Module Utils function} int module_child_dp_read(TModuleDoublePipe dpipe char *msg, size_t maxlen) |
| 3909 |
@findex module_child_dp_read |
| 3910 |
Reads up to @code{maxlen} bytes from the pipe from parent into the buffer @code{msg}. |
| 3911 |
This function is intended, as the prefix says, to be run from the child. |
| 3912 |
Uses the pipes defined in @code{dpipe}. |
| 3913 |
@end deffn |
| 3914 |
|
| 3915 |
@deffn {Module Utils function} int module_parent_dp_read(TModuleDoublePipe dpipe, char *msg, size_t maxlen) |
| 3916 |
@findex module_parent_dp_read |
| 3917 |
Reads up to @code{maxlen} bytes from the pipe from child into the buffer @code{msg}. |
| 3918 |
This function is intended, as the prefix says, to be run from the parent. |
| 3919 |
Uses the pipes defined in @code{dpipe}. |
| 3920 |
@end deffn |
| 3921 |
|
| 3922 |
@deffn {Module Utils function} void module_sigblockall(void) |
| 3923 |
@findex module_sigblockall |
| 3924 |
Blocks all signals. This is intended to be run from the child processes |
| 3925 |
and threads so that their signal handling won't interfere with the |
| 3926 |
parent. |
| 3927 |
@end deffn |
| 3928 |
|
| 3929 |
@deffn {Module Utils function} void module_sigunblockusr(sigset_t *some_signals) |
| 3930 |
@findex module_sigunblockusr |
| 3931 |
Use the set @code{some_signals} to unblock SIGUSR1. |
| 3932 |
@end deffn |
| 3933 |
|
| 3934 |
@deffn {Module Utils function} void module_sigblockusr(sigset_t *some_signals) |
| 3935 |
@findex module_sigblockusr |
| 3936 |
Use the set @code{some_signals} to block SIGUSR1. |
| 3937 |
@end deffn |
| 3938 |
|
| 3939 |
@node Memory Handling Functions, , Multi-process output modules, Module Utils Functions and Macros |
| 3940 |
@subsubsection Memory Handling Functions |
| 3941 |
|
| 3942 |
@deffn {Module Utils function} static void* xmalloc (size_t size) |
| 3943 |
@findex xmalloc |
| 3944 |
The same as the classical @code{malloc()} except that it executes |
| 3945 |
@code{FATAL(``Not enough memory'')} on error. |
| 3946 |
@end deffn |
| 3947 |
|
| 3948 |
@deffn {Module Utils function} static void* xrealloc (void *data, size_t size) |
| 3949 |
@findex xrealloc |
| 3950 |
The same as the classical @code{realloc()} except that it also accepts |
| 3951 |
@code{NULL} as @code{data}. In this case, it behaves as @code{xmalloc}. |
| 3952 |
@end deffn |
| 3953 |
|
| 3954 |
@deffn {Module Utils function} void xfree(void *data) |
| 3955 |
@findex xfree |
| 3956 |
The same as the classical @code{free()} except that it checks |
| 3957 |
if data isn't NULL before calling @code{free()}. |
| 3958 |
@end deffn |
| 3959 |
|
| 3960 |
@node Index Marks in Output Modules, , Module Utils Functions and Macros, Output Modules |
| 3961 |
@subsection Index Marks in Output Modules |
| 3962 |
|
| 3963 |
Output modules need to provide some kind of synchronization and they have to |
| 3964 |
give Speech Dispatcher back some information about what part of the message |
| 3965 |
is currently being said. On the other hand, output modules are not able to tell |
| 3966 |
the exact position in the text because various conversions and message processing take place |
| 3967 |
(sometimes punctuation and spelling substitution, the message needs to be |
| 3968 |
recoded from multibyte to unibyte coding etc.) before the text reaches |
| 3969 |
the synthesizer. |
| 3970 |
|
| 3971 |
For this reason, Speech Dispatcher places so-called index marks in |
| 3972 |
the text it sends to its output modules. They have the form: |
| 3973 |
|
| 3974 |
@example |
| 3975 |
<mark name="id"/> |
| 3976 |
@end example |
| 3977 |
|
| 3978 |
@code{id} is the identifier associated with each index |
| 3979 |
mark. Within a @code{module_speak()} message, each identifier is unique. |
| 3980 |
It consists of the string @code{__spd_} and a counter number. Numbers |
| 3981 |
begin from zero for each message. For example, the fourth index mark |
| 3982 |
within a message looks like |
| 3983 |
|
| 3984 |
@example |
| 3985 |
<mark name="__spd_id_3"/> |
| 3986 |
@end example |
| 3987 |
|
| 3988 |
When an index mark is reached, its identifier should be stored |
| 3989 |
so that the output module is able to tell Speech Dispatcher the identifier |
| 3990 |
of the last index mark. Also, index marks are the best place to stop |
| 3991 |
when the module is requested to pause (although it's ok to stop at |
| 3992 |
some place close by and report the last index mark). |
| 3993 |
|
| 3994 |
Notice that index marks are in SSML format using the @code{mark} tag. |
| 3995 |
|
| 3996 |
@node Download and Contact, Reporting Bugs, Server Programming, Top |
| 3997 |
@chapter Download |
| 3998 |
|
| 3999 |
You can download Speech Dispatcher's latest release source code from |
| 4000 |
@uref{http://www.freebsoft.org/speechd}. There is also information |
| 4001 |
on how to set up anonymous access to our git repository. |
| 4002 |
|
| 4003 |
However, you may prefer to download Speech Dispatcher in a binary |
| 4004 |
package for your system. We don't distribute such packages ourselves. |
| 4005 |
If you run Debian GNU/Linux, it should be in the central repository |
| 4006 |
under the name @code{speech-dispatcher} or @code{speechd}. If you run |
| 4007 |
an rpm-based distribution like RedHat, Mandrake or SuSE Linux, please |
| 4008 |
try to look at @uref{http://www.rpmfind.net/}. |
| 4009 |
|
| 4010 |
If you want to contact us, please look at |
| 4011 |
@uref{http://www.freebsoft.org/contact} |
| 4012 |
or use the email @email{speechd-discuss@@nongnu.org}. |
| 4013 |
|
| 4014 |
@node Reporting Bugs, How You Can Help, Download and Contact, Top |
| 4015 |
@chapter Reporting Bugs |
| 4016 |
|
| 4017 |
If you believe you found a bug in Speech Dispatcher, we will be very |
| 4018 |
grateful if you let us know about it. Please do it by email on the |
| 4019 |
address @email{speechd-discuss@@nongnu.org}, but please don't send us |
| 4020 |
messages larger than half a megabyte unless we ask you. |
| 4021 |
|
| 4022 |
To report a bug in a way that is useful for the developers is not |
| 4023 |
as easy as it may seem. Here are some hints that you should follow in |
| 4024 |
order to give us the best information so that we can find and fix |
| 4025 |
the bug easily. |
| 4026 |
|
| 4027 |
First of all, please try to describe the problem as exactly as you |
| 4028 |
can. We prefer raw data over speculations about where the problem may |
| 4029 |
lie. Please try to explain in what situation the bug happens. Even |
| 4030 |
if it's a general bug that happens in many situations, please try to |
| 4031 |
describe at least one case in as much detail, as possible. |
| 4032 |
|
| 4033 |
Also, please specify the versions of programs that you use when |
| 4034 |
the bug happens. This is not only Speech Dispatcher, but also |
| 4035 |
the client application you use (speechd-el, say, etc.) and |
| 4036 |
the synthesizer name and version. |
| 4037 |
|
| 4038 |
If you can reproduce the bug, please send us the log file also. This |
| 4039 |
is very useful, because otherwise, we may not be able to reproduce the |
| 4040 |
bug with our configuration and program versions that differ from |
| 4041 |
yours. Configuration must be set to logging priority at least 4, but |
| 4042 |
best 5, so that it's useful for debugging purposes. You can do so in |
| 4043 |
@file{etc/speech-dispatcher/speechd.conf} by modifying the variable |
| 4044 |
@code{LogLevel}. Also, you may want to modify the log destination with |
| 4045 |
variable @code{LogFile}. After modifying these options, please restart |
| 4046 |
Speech Dispatcher and repeat the situation in which the bug |
| 4047 |
happens. After it happened, please take the log and attach it to the |
| 4048 |
bug report, preferably compressed using @code{gzip}. But note, that |
| 4049 |
when logging with level 5, all the data that come from Speech Dispatcher |
| 4050 |
is also recorded, so make sure there is no sensitive information |
| 4051 |
when you are reproducing the bug. Please make sure you switch back |
| 4052 |
to priority 3 or lower logging, because priority 4 or 5 produces |
| 4053 |
really huge logs. |
| 4054 |
|
| 4055 |
If you are a programmer and you find a bug that is reproducible in |
| 4056 |
SSIP, you can send us the sequence of SSIP commands that lead to the |
| 4057 |
bug (preferably from starting the connection). You can also try to |
| 4058 |
reproduce the bug in a simple test-script under |
| 4059 |
@file{speech-dispatcher/src/tests} in the source tree. Please check |
| 4060 |
@file{speech-dispatcher/src/tests/README} and see the other tests |
| 4061 |
scripts there for an example. |
| 4062 |
|
| 4063 |
When the bug is a SEGMENTATION FAULT, a backtrace from gdb is also |
| 4064 |
valuable, but if you are not familiar with gdb, don't bother with |
| 4065 |
that, we may ask you to do it later. |
| 4066 |
|
| 4067 |
Finally, you may also send us a guess of what you think |
| 4068 |
happens in Speech Dispatcher that causes the bug, but this is |
| 4069 |
usually not very helpful. If you are able to provide additional technical |
| 4070 |
information instead, please do so. |
| 4071 |
|
| 4072 |
@node How You Can Help, Appendices, Reporting Bugs, Top |
| 4073 |
@chapter How You Can Help |
| 4074 |
|
| 4075 |
If you want to contribute to the development of Speech Dispatcher, |
| 4076 |
we will be very happy if you do so. Please contact us on |
| 4077 |
@email{speechd-discuss@@nongnu.org}. |
| 4078 |
|
| 4079 |
Here is a short, definitively not exhaustive, list of how you can |
| 4080 |
help us and other users. |
| 4081 |
|
| 4082 |
@itemize |
| 4083 |
@item |
| 4084 |
@emph{Donate money:} We are a non-profit organization and we can't work without |
| 4085 |
funding. Brailcom, o.p.s. created Speech Dispatcher, speechd-el and also works |
| 4086 |
on other projects to help blind and visually impaired users of computers. We build |
| 4087 |
on Free Software and GNU/Linux, because we believe this is the right way. But it |
| 4088 |
won't be possible when we have no money. @uref{http://www.freebsoft.org/} |
| 4089 |
|
| 4090 |
@item |
| 4091 |
@emph{Report bugs:} Every user, even if he can't give us money and he is not |
| 4092 |
a programmer, can help us very much by just using our software and telling |
| 4093 |
us about the bugs and inconveniences he encounters. A good user community that |
| 4094 |
reports bugs is a crucial part of development of a good Free Software package. |
| 4095 |
We can't test our software under all circumstances and on all platforms, so each |
| 4096 |
constructive bug report is highly appreciated. You can report bugs in Speech |
| 4097 |
Dispatcher on @email{speechd-discuss@@nongnu.org}. |
| 4098 |
|
| 4099 |
@item |
| 4100 |
@emph{Write or modify an application to support synthesis:} With |
| 4101 |
Speech Dispatcher, we have provided an interface that allows |
| 4102 |
applications easy access to speech synthesis. However powerful, it's |
| 4103 |
no more than an interface, and it's useless on its own. Now it's time |
| 4104 |
to write the particular client applications, or modify existing |
| 4105 |
applications so that they can support speech synthesis. It is useful |
| 4106 |
if the application needs a specific interface for blind people or if |
| 4107 |
it wants to use speech synthesis for educational or other purposes. |
| 4108 |
|
| 4109 |
@item |
| 4110 |
@emph{Develop new voices and language definitions for Festival:} In |
| 4111 |
the world of Free Software, currently Festival is the most promising |
| 4112 |
interface for Text-to-Speech processing and speech synthesis. It's |
| 4113 |
an extensible and highly configurable platform for developing synthetic |
| 4114 |
voices. If there is a lack of synthetic voices or no voices at all for |
| 4115 |
some language, we believe the wisest solution is to try to develop |
| 4116 |
a voice in Festival. It's certainly not advisable to develop your |
| 4117 |
own synthesizer if the goal is producing a quality voice system |
| 4118 |
in a reasonable time. Festival developers provide nice documentation |
| 4119 |
about how to develop a voice and a lot of tools that help doing |
| 4120 |
this. We found that some language definitions can be constructed |
| 4121 |
by canibalizing the already existing definitions and can be tuned |
| 4122 |
later. As for the voice samples, one can temporarily use the |
| 4123 |
MBROLA project voices. But please note that, although they are |
| 4124 |
downloadable for free (as price), they are not Free Software |
| 4125 |
and it would be wonderful if we could replace them by Free Software |
| 4126 |
alternatives as soon as possible. |
| 4127 |
See @uref{http://www.cstr.ed.ac.uk/projects/festival/}. |
| 4128 |
|
| 4129 |
@item |
| 4130 |
@emph{Help us with this or other Free-b-Soft projects:} Please look at |
| 4131 |
@uref{http://www.freebsoft.org} to find information about our |
| 4132 |
projects. There is a plenty of work to be done for the blind and |
| 4133 |
visually impaired people to make their work with computers easier. |
| 4134 |
|
| 4135 |
@item |
| 4136 |
@emph{Spread the word about Speech Dispatcher and Free Software:} You can |
| 4137 |
help us, and the whole community around Free Software, just by telling |
| 4138 |
your friends about the amazing world of Free Software. It doesn't |
| 4139 |
have to be just about Speech Dispatcher; you can tell them about |
| 4140 |
other projects or about Free Software in general. Remember that |
| 4141 |
Speech Dispatcher could only arise out of understanding of some people |
| 4142 |
of the principles and ideas behind Free Software. And this is mostly |
| 4143 |
the same for the rest of the Free Software world. |
| 4144 |
See @uref{http://www.gnu.org/} for more information about GNU/Linux |
| 4145 |
and Free Software. |
| 4146 |
|
| 4147 |
@end itemize |
| 4148 |
|
| 4149 |
@node Appendices, GNU General Public License, How You Can Help, Top |
| 4150 |
@appendix Appendices |
| 4151 |
|
| 4152 |
@node GNU General Public License, GNU Free Documentation License, Appendices, Top |
| 4153 |
@appendix GNU General Public License |
| 4154 |
@center Version 2, June 1991 |
| 4155 |
@cindex GPL, GNU General Public License |
| 4156 |
|
| 4157 |
@include gpl.texi |
| 4158 |
|
| 4159 |
@node GNU Free Documentation License, Index of Concepts, GNU General Public License, Top |
| 4160 |
@appendix GNU Free Documentation License |
| 4161 |
@center Version 1.2, November 2002 |
| 4162 |
@cindex FDL, GNU Free Documentation License |
| 4163 |
|
| 4164 |
@include fdl.texi |
| 4165 |
|
| 4166 |
@node Index of Concepts, , GNU Free Documentation License, Top |
| 4167 |
@unnumbered Index of Concepts |
| 4168 |
|
| 4169 |
@cindex tail recursion |
| 4170 |
@printindex cp |
| 4171 |
|
| 4172 |
@bye |
| 4173 |
|
| 4174 |
@c LocalWords: texinfo setfilename speechd settitle finalout syncodeindex pg |
| 4175 |
@c LocalWords: setchapternewpage cp fn vr texi dircategory direntry titlepage |
| 4176 |
@c LocalWords: Cerha Hynek Hanke vskip pt filll insertcopying ifnottex dir fd |
| 4177 |
@c LocalWords: API SSIP cindex printf ISA pindex Flite Odmluva FreeTTS TTS CR |
| 4178 |
@c LocalWords: ViaVoice Lite Tcl Zandt wxWindows AWT spd dfn backend findex |
| 4179 |
@c LocalWords: src struct gchar gint const OutputModule intl FDSetElement len |
| 4180 |
@c LocalWords: fdset init flite deffn TFDSetElement var int enum EVoiceType |
| 4181 |
@c LocalWords: sayf ifinfo verbatiminclude ref UTF ccc ddd pxref LF cs conf |
| 4182 |
@c LocalWords: su AddModule DefaultModule xref identd printindex Dectalk GTK |
| 4183 |
|
| 4184 |
@c speechd.texi ends here |
| 4185 |
@c LocalWords: emph soundcard precision archieved success Dispatcher When |