# The &ktts; Handbook

Jeremy
Whiting
jpwhiting@kde.org
Gary
R.
Cramblitt
garycramblitt@comcast.net
2009
Jeremy Whiting
2004-2005
Gary R. Cramblitt
&FDLNotice;
2009-12-25
0.4.0 (&kde; 4.4)

&ktts; - the &kde; Text-to-Speech system - is a plugin based service that allows any &kde; (or non-&kde;) application to speak using the &DBus; interface.

&ktts; intends to be the implementation for the &kde; Text-to-Speech API.

KDE
accessibility
kdeaccessibility
TTS
Text-to-Speech
KTTSD
kttsmgr
festival
flite
hadifix
MBROLA
freetts
epos
SSML

## Introduction

&ktts; is a subsysem within &kde; for producing Text-to-Speech (TTS). It provides a common API for &kde; programmers to give TTS capabilities to their applications. It provides some nice capabilities for end users as well.

User features:

- Speak contents of a text file.

- Speak &kde; notification events (KNotify).

- Speak all or part of the text of a web page in &konqueror;.

- Speak all or part of the text in &kate; text editor, including instances where &kate; is embedded in another &kde; application.

- Speech is spoken via speech-dispatcher, so any speech-dispatcher backend can be used (espeak, festival, &etc;)

- User-configurable filters for substituting misspoken words, choosing speech synthesizers, and transforming XHMTL/&XML; documents.

Programmer features:

- Priority system for screen reader outputs, warnings and messages, while still playing regular texts.

- Permit generation of speech from the command line (or via shell scripts) using the &qdbus; utility.

- Provide a lightweight and easily usable interface for applications to generate speech output.

- Applications need not be concerned about contention over the speech device.

- FUTURE: Provide support for speech markup languages, such as VoiceXML, Sable, &Java; Speech Markup Language (JSML), and Speech Markup Meta-language (SMML).

- FUTURE: Provide limited support for embedded speech markers.

- Asynchronous to prevent system blocking.

&ktts; actually consists of several programs:

`kttsd`

  the &kde; Text-to-Speech Daemon, which is a non-&GUI; application that provides TTS services to applications via &DBus;.

`kttsmgr`

  a &GUI; application for configuring and controlling kttsd. kttsmgr sits in the system tray.

`libkhtmlkttsdplugin`

  A plugin for the &konqueror; web browser that permits you to speak all or a portion of the text on a web page.

`ktexteditor_kttsd`

  A plugin for the &kate; text editor that permits you to speak all or a portion of a text file.

### Support

In addition to the &kde; Bugzilla database ( http://bugs.kde.org/ ), discussions for &ktts; currently take place in the kde-accessibility mailing list. Subscribe at https://mail.kde.org/mailman/listinfo/kde-accessibility. Developers also hang out in IRC (irc.kde.org, channel #kde-accessibility).

## Using &ktts;

Before you can use &ktts;, you must install speech-dispatcher and make sure it is working. See .

### Starting `kttsmgr`

To start the &ktts; system, type the following command in a &konsole;

`kttsmgr`

or click on kttsmgr in the &kde; Menu.

If this is the first time running `kttsmgr`, or if you have not yet configured any talkers, the Talkers screen appears. See . If you have already configured at least one talker, the General screen appears. See .

### Configuring Talkers

Most text-to-speech (TTS) synthesizers offer multiple languages and voices and may offer multiple speaking genders, volumes, and rates. You may configure more than one instance of a synthesizer. Each combination of language, synthesizer, voice, gender, volume, and rate is called a talker. You should configure at least one talker before you use &ktts; otherwise speech-dispatcher will use a default voice.

Multiple talkers for the same synthesizer is similar to multiple print queues for a single physical printer.

When you click the Talkers tab in `kttsmgr`, the Talkers screen appears. This screen also automatically appears if you start `kttsmgr` and you have not yet configured any talkers.

The &kde; Text-to-Speech Manager (Talkers tab). The &kde; Text-to-Speech Manager (Talkers tab)

Click to add a new talker.

All the configured Talkers are listed here. Highest priority Talkers are listed at the top. The top-most talker will be used to do the speaking when an application does not specify a talker.

Click on a talker in the list to highlight it and click this button to remove it.

Click on a talker in the list to highlight it and click this button to change its configuration. See below.

Click on a talker in the list to highlight it and click this button to move it down one row in the list. The lower a talker appears in the list, the lower its priority.

Click one of these buttons to apply the changes you have made to the running &ktts; system.

When you click the Add button, the Add Talker screen appears.

Add Talker screen. Add Talker screen

You should give your new talker a name, this can be anything.

Choose the language and synthesizer here.

Choose the voice type here, there are three Male, three Female, one Male Child and one Female Child voices to choose from.

Set any custom voice parameters here.

When you click here your new talker will appear in the list in the Talkers screen. Click the Edit button to edit the talker's configuration.

You are almost ready to begin using &ktts;. Now go back to the General tab and check the Enable Text-to-Speech System (KTTSD) box. This will start the &kde; TTS Daemon. See . You may now begin using &ktts; to speak text. Click the Jobs tab to create and manage text jobs. See .

### Starting KTTSD and Setting General Options

Once you have configured at least one talker, you can start the &kde; Text-to-Speech System. Click on the General tab. The General screen appears. You can also set some general options on this screen.

The &kde; Text-to-Speech Manager (General tab). The &kde; Text-to-Speech Manager (General tab)

Check this box to activate the &ktts; system. This starts the &kde; TTS Daemon (KTTSD). If KTTSD starts successfully, the Jobs tab will appear. Once KTTSD has been started, you can begin creating and speaking text jobs. See . Unchecking will stop KTTSD and deactivate the &kde; TTS system.

When this box is checked, an icon appears in the system tray whenever `kttsmgr` is running. In this mode, clicking OK or Cancel does not cause `kttsmgr` to exit. Instead, the screen disappears but `kttsmgr` continues running in the system tray. Click the icon to restore the screen. To quit `kttsmgr`, right-click on the icon in the system tray and choose Quit. When unchecked, an icon does not appear in the system tray. Clicking OK or Cancel quits `kttsmgr`.

When `kttsmgr` exits, &ktts; keeps running if the Enable Text-to-Speech System (KTTSD) box is checked.

This option does not take effect until the next time `kttsmgr` is started.

This option has no effect when `kttsmgr` is running in the &kcontrol;.

When this box is checked, and `kttsmgr` automatically appears in the system tray whenever speaking, it will also disappear automatically when speaking has finished.

Be sure to click here to save your settings.

### Managing Text Jobs

When you click the Jobs tab in `kttsmgr`, the Jobs screen appears.

The &kde; Text-to-Speech Manager (Jobs tab).
The &kde; Text-to-Speech Manager (Jobs tab)

The controls here allow you to change attributes of the currently speaking voice.

The buttons in this row permit you to stop, cancel, pause and resume the current text job.

The buttons in this row permit you to speak the text currently in the &kde; clipboard, or open a text file for speaking. You can also change the talker for a job.

When you click OK or Apply, all changes to settings on other screens are applied (if any).

The Jobs tab only appears when KTTSD is running. If you do not see the Jobs tab, click on the General tab and check the Enable Text-to-Speech (KTTSD) box.

### Speaking Text from Web Pages

While running the &kde; &konqueror; web browser, you can speak the text of the web page displayed. First ensure that &ktts; is running. Highlight the text you want spoken and choose Tools Speak Text on the main menu. After a moment, the highlighted text should begin speaking.

It is almost always a good idea to highlight the text on the web page you want spoken. You can skip this step, but you will hear a lot of &HTML; headers and other invisible tags spoken.

### Speaking Text from &kate; Text Editor

While running the &kde; Advanced Text Editor (&kate;), you can speak the text displayed. First ensure that &ktts; is running. Highlight the text you want spoken and choose Tools Speak Text on the main menu. After a moment, the highlighted text should begin speaking.

You do not have to first highlight text. In this case, the entire file will be spoken.

This also works when &kate; is running embedded in another application, such as &konqueror; or &quanta;.

### Speaking Notifications (KNotify)

KNotify is the notification subsystem within &kde;, which alerts you to events you configure within the &kde; system. You can configure &ktts; to speak text notifications.

For example, &konversation;, a &kde; IRC application, permits you to configure a wide variety of notifications. For instance, you can tell &konversation; to notify you whenever a message appears in an IRC channel with your nickname in it. Together with &ktts; you can have &kde; speak the text of the IRC message to you.

In general, if a &kde; application supports KNotify, a Notifications menu item will appear under the application's Settings menu. The specifics for configuring each application with KNotify vary from application to application.

String Replacer filters are a good way to clean up messages sent from applications if they are mispronounced or misspoken in &ktts;. The `kmail.xml` file, which comes with &ktts;, is a good example. It removes `br`, and `b` tags from the &kmail; notification messages and also removes the phrase `/local/inbox/`, since this may be safely assumed in most cases. See .

### Filters (Advanced)

Filters are an advanced feature of &ktts;. For the basic operation of &ktts;, they are not needed.

Filters are used to pre-process text before it is sent to speech-dispatcher. They are useful for enhancing speech, substituting for misspoken words or abbreviations, choosing the appropriate language and talker to do the speaking, or working around certain limitations of speech synthesizers and their voices.

#### Types of &ktts; Messages

To understand how to use filters, it is helpful to first understand how text is processed by speech-dispatcher. Text spoken by &ktts; is of four possible types.

- Screen Reader Output.

- Warnings.

- Messages

- Text Jobs

The type is determined by the application that sends the text to &ktts;.

Screen Reader Output has the highest priority. It is reserved for use by Screen Reader applications. Screen Reader Output preempts all other messages, causing those jobs to pause. Once the Screen Reader Output has been spoken, the preempted messages will automatically resume.

Warnings are the next highest priority. It is reserved for high-priority messages, such as "CPU is over-heating." A Warning will preempt Messages and regular text, causing those jobs to pause. Once the Warning has been spoken, the preempted messages will automatically resume.

Messages are the next highest priority. A Message will preempt regular text jobs. &kmouth; is an example of an application that uses Messages. For example, while reading out long text from a web page, &kmouth; can be used to greet someone who walks into the room. &kde; Notifications are also Messages (see ).

The rest are ordinary Text Jobs. Any job you initiate from the Jobs tab is a Text Job. KSayit is an example of an application that uses Text Jobs. Text Jobs are intended for longer speech output that is not urgent.

All four kinds of jobs are queues, except for Screen Reader Output. If a Screen Reader Output is sent from an application while &ktts; is speaking another Screen Reader Output, the speaking message is stopped and discarded.

#### Types of Filters

The first thing you must know about filters is that they are never applied to Screen Reader Output. They are applied to Warnings, Messages, and Text jobs, and also &kde; notifications (KNotify).

Filters process the text and pass it on to the next filter. There are currently three kinds of filters.

- String Replacers.

- &XML; Transformers

- Talker Choosers.

Filters are implemented using a plugin architecture. In the future, there may be additional kinds of filters.

String Replacer filters substitute pieces of text with other text. The replaced pieces are matched either as words or as regular expressions. &ktts; comes with pre-defined String Replacer filters for speaking abbreviations, speaking chat emoticons, such as ":-)", or reformatting notification messages from &konversation; or &kmail; into a more understandable form.

&XML; Transformers use an &XML; Style Language - Transforms (XSLT) file to convert &XML; of one format to another format. &ktts; comes with a couple of XSLT files for converting &XHTML; into SSML.

Talker Choosers permit you redirect jobs to a talker based on the contents of the text, or upon the application that sent it to &ktts;. For example, if you have configured a female talker in the Talkers tab, you can direct text coming from KSayIt to that talker. See .

Each of these kinds of filters has configurable rules for when the filter should apply itself to the text to be spoken. If the filter determines that it should not apply itself, the text is passed on to the next filter unaltered.

When a Text Job, Message, Warning, or &kde; Notification message is sent to &ktts;, it passes through each of the enabled filters you have configured in the screen below. The order is from top to bottom.

#### Configuring Filters

To use filters, click the Filters tab in `kttsmgr`.

The &kde; Text-to-Speech Manager (Filters tab). The &kde; Text-to-Speech Manager (Filters tab)

This is the list of configured ordinary filters. If unchecked, the filter is inactive and will be bypassed. Filters are applied in the order specified here, top to bottom.

Click here to add a new filter. You will be prompted for the kind of filter to add. After choosing the kind, see the configuration dialogs below.

Click here to remove a filter.

Click here to change the configuration of a filter. See the configuration dialogs below.

Click these buttons to move a filter up or down in the list.

Be sure to click here, otherwise your settings will not take effect.

#### Configuring String Replacer Filters

You configure String Replacer filters by supplying a list of words or regular expressions to be matched. When the matched words or regular expressions are found in the text, each is replaced by a substitute string you supply.

String Replacer String Replacer

Enter a name for your filter. Use any name you like that distinquishes it from all other filters.

This is the list of words and regular expressions. The filter searches for matches on each string in the Match column, replacing the matched string with the string in the Replace With column. The list is processed in the order displayed, top to bottom.

Click here to add another word or regular expression to the list.

Click here to move the currently highlighted word or regular expression up or down in the list.

Click to change an existing word or regular expression in the list.

Click to remove the currently highlighted word or regular expression from the list.

Use these buttons to load a list of words or regular expression from a file, save the current list to a file, or clear the entire list. When loading from a file, the items in the file are appended to the existing list.

If not blank, the filter will apply itself only if the job's talker language matches the language you enter here. Click the button to display a list of languages. You may select more than one language by pressing &Ctrl; while clicking.

If not blank, the filter will apply itself only if the text came from one of the applications listed. You may enter more than one application separated by commas. Example: ``konversation,kmail``

You can discover the Application ID of running programs using the `&qdbus;` program. You should leave the &DBus; numbers out. For example, if &qdbus; shows an Application ID of `kopete-3432`, you would just enter ``kopete``.

The String Replacer filter will only apply itself to the text if all non-blank conditions are met in the Apply This Filter When box. If all the boxes are blank, the filter will apply to all text.

When matching words, the String Replacer filter internally uses a regular expression of the form `\s`word`\s`. In other words, the word must have word boundaries (spaces) on either side of it.

A discussion on how to write regular expressions is outside the scope of this handbook. If you have the &kde; Regular Expression editor installed, there is a button available on the Add or Edit screens that will assist you at constructing regular expressions. The &kde; Regular Expression Editor is part of the `kdeutils` package.

&ktts; comes with a few word list files, including a list of emoticons, such as ":-)", some abbreviations typically used in IRC or instant messaging applications, and a list of other abbreviations. There is also a list of special characters which the current version of the Polish Festival voice cannot handle. If you develop useful word lists of your own, use the Save button to save them to a file and send them to the &ktts; team for inclusion in the next version.

#### Configuring &XML; Transformer Filters

The &XML; Transformer filter uses XSLT files to transform &XML; from one format to another. XSLT, the &XML; Style Language - Transforms, is a W3C standard language for performing such transformations. It can only be used on well-formed &XML;. You must have the `xsltproc` utility installed.

&XML; Transformer &XML; Transformer

Enter a name for your filter. Use any name you like that distinquishes it from all other filters.

Enter the full path to an existing XSLT file, which will perform the transformation.

Specify the path to the `xsltproc` utility. If xsltproc is in your environment PATH, simply enter ``xsltproc``.

If not blank, the filter will apply itself only if the &XML; has the specified root element or a `<!DOCTYPE` specification beginning with the entered string. This distinquishes one form of &XML; from another. For example, ``html`` in the DOCTYPE box will match `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">`.

If not blank, the filter will apply itself only if the text came from one of the applications listed. You may enter more than one application separated by commas. Example: ``konversation,kmail``

You can discover the Application ID of running programs using the `&qdbus;` program. You should leave the &DBus; numbers out. For example, if &qdbus; shows an Application ID of `kopete-3432`, you would just enter ``kopete``.

The &XML; Transformer filter will only apply itself to the text if the specified root element or DOCTYPE are met and if the application ID is met in the Apply This Filter When box. If an item in this box is blank, the test is not performed, so if all the boxes are blank, the filter will apply itself to all text. However, you should fill in at least one box, since many text jobs will not be in &XML; format.

#### Configuring Talker Chooser Filters

Talker Chooser filters are used to direct the text to a desired talker configured in the Talker tab, or to any talker having specified attributes. For example, you can specify that text coming from `kmail` should be spoken using a talker configured with a female voice. See .

Just before &ktts; begins sending text to each of the filters, it picks a talker to speak the text. The talker chosen is based on the talker attributes specified by the application that sent the text to &ktts; and the attributes of the talkers that you have configured on the Talkers tab. The Talker Chooser filter permits you to override the chosen talker.

Talker Chooser Talker Chooser

Enter a name for your filter. Use any name you like that distinquishes it from all other filters.

If not blank, the filter will apply itself only if the text contains the entered regular expression. If it is installed, click the browse button to launch the &kde; Regular Expression Editor to assist you at entering the regular expression.

For better performance, try to "anchor" the regular expression to the start of the string. In other words, start your regular expression with ``^``.

If not blank, the filter will apply itself only if the text came from one of the applications listed. You may enter more than one application separated by commas. Example: ``konversation,kmail``

You can discover the Application ID of running programs using the `&qdbus;` program. You should leave the &DBus; numbers out. For example, if &qdbus; shows an Application ID of `kopete-3432`, you would just enter ``kopete``.

Specify the attributes of the talker you prefer to speak the text here. If the text meets the filter conditions above, a talker will be chosen that most closely matches the attributes you specify here. Click the button at the right to display the Select Talker screen.

Use these buttons to save your Talker Chooser settings, load settings from a saved file, or clear all the settings.

The Talker Chooser filter will only apply itself to the text if all non-blank conditions are met in the Apply This Filter When box. You must fill in at least one of the boxes.

## Command Reference

TODO

## Developer's Guide to &ktts;

&ktts; has two Application Programmer Interfaces (APIs):

- The &kde; Text-to-Speech API, which is used by application programmers to give their applications TTS capabilities. Applications communicate with KTTSD via &DBus;.

- The KTTSD Plugin API, which is used to add speech synthesis plugins to KTTSD so that &ktts; will work with a new speech synthesis engine.

The following section gives a short description of the &kde; Text-to-Speech API &DBus; Interface. Full documentation for both APIs is available online at the &kde; Accessibility web site (http://accessibility.kde.org).

### The &ktts; &DBus; Interface

Applications communicate requests for Text-to-Speech services via the &kde; &DBus; interface to program `kttsd` object `KSpeech`.

Enter the following commands in a &konsole;.

If KTTSD is not already running

`kttsd`

To queue a text job to be spoken

`qdbus org.kde.kttsd /KSpeech say "text" "options"`

where `text` is the text to be spoken, and `options` is a language code such as `en`, `cy`, &etc;

Example.

`qdbus org.kde.kttsd /KSpeech say "This is a test." "en"`

There are many more commands that can be sent. To see a list of possible commands,

`qdbus org.kde.kttsd /KSpeech`

or read the &kde; Text-to-Speech API online.

## Questions and Answers

&reporting.bugs; &updating.documentation;

I need to start over. How do I get &ktts; completely terminated?

Enter the following commands in a &konsole;:

    killall kttsd
    killall kttsmgr

How can I see debugging output from `kttsd`?

Open two &konsole; windows. First start `kttsd` in one window, then start `kttsmgr` in the second.

None of the supported speech synthesizers support the language I need. Where can I get a synth for my language?

Google(tm) is your friend. This link might also help. If you find a free synthesis engine that supports your desired language, and want to add support for it to &ktts;, please contact the development team. Open source engines are especially welcome. If you know of a commercial synth, perhaps you can persuade the vendor to donate a free copy to the &ktts; development team. In the meantime, you may be able to get the synth working using speech-dispatchers command backend.

I have the &HTML; &XML; Transformer filter configured, but web pages are not spoken at all using the Festival plugin.

Due to a bug in Festival 1.95 beta, you must install the `rab_diphone` (British male) voice for SABLE to work at all, even if you are not using that voice to speak the web pages. Also, make sure the `xsltproc` utility is installed and in the PATH.

Certain characters or punctuation seem to be producing errors in the synthesizer, making it skip entire sentences, or pronounce gibberish. What can I do?

First, make sure the Character encoding option in the talker's configuration dialog is properly set for the language. If certain words or characters are causing problems, a String Replacer filter might help. See .

## Credits and License

&ktts;

Program Copyright © 2002 José Pablo Ezequiel "Pupeno" Fernández pupeno@kde.org

Current Maintainer: Jeremy Whiting jpwhiting@kde.org

Contributors:

- Gary Cramblitt garycramblitt@comcast.net

- Olaf Schmidt ojschmidt@kde.org

- Gunnar Schmi Dt gunnar@schmi-dt.de

- Paul Giannaros ceruleanblaze@gmail.com

Documentation Copyright © 2009 Jeremy Whiting jpwhiting@kde.org © 2004 Gary R. Cramblitt garycramblitt@comcast.net

&underFDL;

&underGPL;

Speech synthesis engines used by &ktts; have their own licenses. See each engine's documentation or website for details. Some voices also have their own licensing.

## Installation

### How to obtain &ktts;

&install.intro.documentation;

Debian Install Command: `apt-get install kdeaccessibility`

You will find links to source and binary packages on the &kde; Accessibility web site (http://accessibility.kde.org).

If you have access to the &kde; code repository, you can download &ktts; by checking out the `kdeaccessibility` module. &ktts; will be found in the `kttsd` folder. You can also download tarballs of the kdeaccessibility source code from ftp://ftp.kde.org/pub/kde/

### Requirements

Mandatory requirements:

- &kde; version 4.4 or later.

- speech-dispatcher version 0.67 or later.

- A speech synthesizer. The following synthesizers and spoken languages are currently supported.

  Espeak | Most languages, check http://espeak.sourceforge.net/languages.html for the current list of supported languages
  Festival | American English, British, Spanish, German, Finnish, Czech, Polish, Russian, Italian, French Canadian, Kiswahili, Zulu, and Ibibio

  It also works with any synthesis engine that can be run from a command in a &konsole;.

  The languages listed above may not be comprehensive or up-to-date. Check the specifications for each engine for a complete list of supported languages. Also check the &ktts; website for additional information that might not have made it into this handbook.

  speech-dispatcher uses a flexible plugin architecture for speech synthesis engines. If you want to enhance &ktts; to support another engine, contact the development team.

  See for specific instructions for each of these engines.

Optional components:

- The `xsltproc` utility is needed for SSML support and for the &XML; Transformer filter, but not required. Debian users can install xsltproc with the command `apt-get install xsltproc`.

### Compilation and Installation

In order to compile &ktts;, you must have a recent (&kde; 4.4 or greater) copy of the &kde; development files, including kdelibs and the development files for speech-dispatcher.

If you downloaded the &ktts; source from the `kdeaccessibility` code repository module, or downloaded the nightly tarball, use the following commands to compile and install.

    cd kdeaccessibility
    mkdir build
    cd build
    cmake ../
    make
    sudo make install

### Configuration

Make sure speech-dispatcher is working with your speech synthesis engine before using &ktts;. The shell script spd-conf can be used for that.

&ktts; in &kde; 4.4 is a first attempt at porting &ktts; to use speech-dispatcher. In the future kttsmgr will be able to configure speech-dispatcher directly without spd-conf.

&documentation.index;