home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kspeech.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  56.2 KB  |  1,287 lines

  1. /***************************************************** vim:set ts=4 sw=4 sts=4:
  2.   kspeech.h
  3.   KTTSD DCOP Interface
  4.   --------------------
  5.   Copyright:
  6.   (C) 2002-2003 by Jos├⌐ Pablo Ezequiel "Pupeno" Fern├índez <pupeno@kde.org>
  7.   (C) 2003-2004 by Olaf Schmidt <ojschmidt@kde.org>
  8.   (C) 2004-2005 by Gary Cramblitt <garycramblitt@comcast.net>
  9.   -------------------
  10.   Original author: Jos├⌐ Pablo Ezequiel "Pupeno" Fern├índez
  11.  ******************************************************************************/
  12.  
  13. /***************************************************************************
  14.  *                                                                         *
  15.  *   This program is free software; you can redistribute it and/or modify  *
  16.  *   it under the terms of the GNU General Public License as published by  *
  17.  *   the Free Software Foundation; version 2 of the License.               *
  18.  *                                                                         *
  19.  ***************************************************************************/
  20.  
  21. #ifndef _KSPEECH_H_
  22. #define _KSPEECH_H_
  23.  
  24. #include <dcopobject.h>
  25. #include <qstringlist.h>
  26.  
  27. /**
  28.  * @interface KSpeech
  29.  *
  30.  * kspeech - the KDE Text-to-Speech API.
  31.  *
  32.  * @version 1.0 Draft 10
  33.  *
  34.  * @since KDE 3.4
  35.  *
  36.  * This class defines the DCOP interface for applications desiring to speak text.
  37.  * Applications may speak text by sending DCOP messages to application "kttsd" object "KSpeech".
  38.  *
  39.  * %KTTSD -- the KDE Text-to-Speech Deamon -- is the program that supplies the services
  40.  * in the KDE Text-to-Speech API.
  41.  *
  42.  * @warning The KSpeech interface is still being developed and is likely to change in the future.
  43.  *
  44.  * @section Features
  45.  *
  46.  *   - Priority system for Screen Readers, warnings and messages, while still playing
  47.  *     regular texts.
  48.  *   - Long text is parsed into sentences.  User may backup by sentence or part,
  49.  *     replay, pause, and stop playing.
  50.  *   - Handles multiple speaking applications.  Text messages are treated like print jobs.
  51.  *     Jobs may be created, started, stopped, paused, resumed, and deleted.
  52.  *   - Speak contents of clipboard.
  53.  *   - Speak KDE notifications.
  54.  *   - Plugin-based text job filtering permits substitution for misspoken words,
  55.  *     abbreviations, etc., transformation of XML or XHTML to SSML, and automatic
  56.  *     choice of appropriate synthesis engine.
  57.  *
  58.  * @section Requirements
  59.  *
  60.  * You may build any KDE application to use KSpeech, since the interface is in kdelibs, but
  61.  * the kdeaccessibility package must be installed for KTTS to function.
  62.  *
  63.  * You will need a speech synthesis engine, such as Festival.  See the KTTS Handbook
  64.  * for the latest information on installing and configuring speech engines and voices
  65.  * with KTTS.
  66.  *
  67.  * @section goals Design Goals
  68.  *
  69.  * The KDE Text-to-Speech API is designed with the following goals:
  70.  *
  71.  *   - Support the features enumerated above.
  72.  *   - Plugin-based architecture for support of a wide variety of speech synthesis
  73.  *     engines and drivers.
  74.  *   - Permit generation of speech from the command line (or via shell scripts)
  75.  *     using the KDE DCOP utilities.
  76.  *   - Provide a lightweight and easily usable interface for applications to
  77.  *     generate speech output.
  78.  *   - Applications need not be concerned about contention over the speech device.
  79.  *   - Provide limited support for speech markup languages, such as Sable,
  80.  *     Java %Speech Markup Language (JSML), and %Speech Markup Meta-language (SMML).
  81.  *   - Provide limited support for embedded speech markers.
  82.  *   - Asynchronous to prevent system blocking.
  83.  *   - Plugin-based audio architecture.  Currently supports aRts but will support
  84.  *     additional audio engines in the future, such as gstreamer.
  85.  *   - Compatible with original %KTTSD API as developed by Jos├⌐ Pablo Ezequiel
  86.  *     "Pupeno" Fern├índez (avoid breaking existing applications).
  87.  *
  88.  * Architecturally, applications interface with %KTTSD, which performs queueing,
  89.  * speech job managment, plugin management and sentence parsing.  %KTTSD interfaces with a
  90.  * %KTTSD speech plugin(s), which then interfaces with the speech engine(s) or driver(s).
  91.  *
  92.    @verbatim
  93.          application
  94.               ^
  95.               |  via DCOP (the KDE Text-to-Speech API)
  96.               v
  97.             kttsd
  98.               ^
  99.               |  KTTSD plugin API
  100.               v
  101.          kttsd plugin
  102.               ^
  103.               |
  104.               v
  105.         speech engine
  106.    @endverbatim
  107.  *
  108.  * The %KTTSD Plugin API is documented in PluginConf in the kdeaccessibility module.
  109.  *
  110.  * There is a separate GUI application, called kttsmgr, for providing %KTTSD
  111.  * configuration and job management.
  112.  *
  113.  * kttsd maintains 4 types of speech output:
  114.  *   - Screen Reader Output
  115.  *   - Warnings
  116.  *   - Messages
  117.  *   - Text Jobs
  118.  *
  119.  * Method sayScreenReaderOutput speaks Screen Reader output.
  120.  * It pre-empts any other speech in progress,
  121.  * including other Screen Reader outputs, i.e., it is not a queue.
  122.  * This method is reserved for use by Screen Readers.
  123.  *
  124.  * Methods sayWarning and sayMessage place messages into the Warnings and
  125.  * Messages queues respectively.  Warnings take priority over messages, which take priority
  126.  * over text jobs.  Warnings and messages are spoken when the currently-speaking
  127.  * sentence of a text job is finished.
  128.  *
  129.  * setText places text into the text job queue. startText begins speaking jobs.
  130.  * When one job finishes, the next job begins.  Method appendText adds
  131.  * additional parts to a text job.  Within a text job, the application (and user
  132.  * via the kttsmgr GUI), may back up or advance by sentence or part, or rewind
  133.  * to the beginning.
  134.  * See jumpToTextPart and moveRelTextSentence.
  135.  * Text jobs may be paused, stopped, and resumed or deleted from the queue.
  136.  * See pauseText, stopText, resumeText, and removeText.
  137.  *
  138.  * @section cmdline DCOP Command-line Interface
  139.  *
  140.  * To create a text job to be spoken
  141.  *
  142.    @verbatim
  143.      dcop kttsd KSpeech setText <text> <talker>
  144.    @endverbatim
  145.  *
  146.  * where \<text\> is the text to be spoken, and \<talker\> is usually a language code
  147.  * such as "en", "cy", etc.
  148.  *
  149.  * Example.
  150.  *
  151.    @verbatim
  152.      dcop kttsd KSpeech setText "This is a test." "en"
  153.    @endverbatim
  154.  *
  155.  * To start speaking the text.
  156.  *
  157.    @verbatim
  158.      dcop kttsd KSpeech startText 0
  159.    @endverbatim
  160.  *
  161.  * You can combine the setText and startText commands into a single command.
  162.  *
  163.    @verbatim
  164.      dcop kttsd KSpeech sayText <text> <talker>
  165.    @endverbatim
  166.  *
  167.  * @since KDE 3.5
  168.  *
  169.  * To stop speaking and rewind to the beginning of the text.
  170.  *
  171.    @verbatim
  172.      dcop kttsd KSpeech stopText 0
  173.    @endverbatim
  174.  *
  175.  * Depending upon the speech plugin used, speaking may not immediately stop.
  176.  *
  177.  * To stop and remove a text job.
  178.  *
  179.    @verbatim
  180.      dcop kttsd KSpeech removeText 0
  181.    @endverbatim
  182.  *
  183.  * Note: For more information about talker codes, see talkers below.
  184.  *
  185.  * @section programming Calling KTTSD from a Program
  186.  *
  187.  * There are two methods of making DCOP calls from your application to %KTTSD.
  188.  *
  189.  *   - Manually code them using dcopClient object.  See kdebase/konqueror/kttsplugin/khtmlkttsd.cpp
  190.  *     for an example.  This method is recommended if you want to make a few simple calls to KTTSD.
  191.  *   - Use kspeech_stub as described below.  This method generates the marshalling code for you
  192.  *     and is recommended for a more complex speech-enabled applications.  kcmkttsmgr in the
  193.  *     kdeaccessibility module is an example that uses this method.
  194.  *
  195.  * To make DCOP calls from your program using kspeech_stub, follow these steps:
  196.  *
  197.  * 1.  Include kspeech_stub.h in your code.  Derive an object from the KSpeech_stub interface.
  198.  *     For example, suppose you are developing a KPart and want to call %KTTSD.
  199.  *     Your class declaration might look like this:
  200.  *
  201.    @verbatim
  202.      #include <kspeech_stub.h>
  203.      class MyPart: public KParts::ReadOnlyPart, public KSpeech_stub {
  204.    @endverbatim
  205.  *
  206.  * 2.  In your class constructor, initialize DCOPStub, giving it the sender
  207.  *     "kttsd", object "KSpeech".
  208.  *
  209.    @verbatim
  210.      MyPart::MyPart(QWidget *parent, const char *name) :
  211.         KParts::ReadOnlyPart(parent, name),
  212.         DCOPStub("kttsd", "KSpeech") {
  213.    @endverbatim
  214.  *
  215.  * 3.  See if KTTSD is running, and if not, start it.
  216.  *
  217.    @verbatim
  218.      DCOPClient *client = dcopClient();
  219.      client->attach();
  220.      if (!client->isApplicationRegistered("kttsd")) {
  221.          QString error;
  222.          if (KApplication::startServiceByDesktopName("kttsd", QStringList(), &error))
  223.              cout << "Starting KTTSD failed with message " << error << endl;
  224.      }
  225.    @endverbatim
  226.  *
  227.  * If you want to detect if KTTSD is installed without starting it, use this code.
  228.  *
  229.    @verbatim
  230.      KTrader::OfferList offers = KTrader::self()->query("DCOP/Text-to-Speech", "Name == 'KTTSD'");
  231.      if (offers.count() > 0)
  232.      {
  233.        // KTTSD is installed.
  234.      }
  235.    @endverbatim
  236.  *
  237.  * Typically, you would do this to hide a menu item or button if KTTSD is not installed.
  238.  *
  239.  * 4.  Make calls to KTTSD in your code.
  240.  *
  241.    @verbatim
  242.      uint jobNum = setText("Hello World", "en");
  243.      startText(jobNum);
  244.    @endverbatim
  245.  *
  246.  * 4.  Add kspeech_DIR and kspeech.stub to your Makefile.am.  Example:
  247.  *
  248.    @verbatim
  249.      kspeech_DIR = $(kde_includes)
  250.      libmypart_la_SOURCES = kspeech.stub
  251.    @endverbatim
  252.  *
  253.  * @section signals Signals Emitted by KTTSD
  254.  *
  255.  * %KTTSD emits a number of DCOP signals, which provide information about sentences spoken,
  256.  * text jobs started, stopped, paused, resumed, finished, or deleted and markers seen.
  257.  * In general, these signals are broadcast to any application that connects to them.
  258.  * Applications should check the appId argument to determine whether the signal belongs to
  259.  * them or not.
  260.  *
  261.  * To receive %KTTSD DCOP signals, follow these steps:
  262.  *
  263.  * 1.  Include kspeechsink.h in your code.  Derive an object from the KSpeechSink interface
  264.  *     and declare a method for each signal you'd like to receive.  For example,
  265.  *     if you were coding a KPart and wanted to receive the KTTSD signal sentenceStarted:
  266.  *
  267.    @verbatim
  268.      #include <kspeechsink.h>
  269.      class MyPart:
  270.          public KParts::ReadOnlyPart,
  271.          virtual public KSpeechSink
  272.      {
  273.          protected:
  274.             ASYNC sentenceStarted(const QCString& appId, const uint jobNum, const uint seq);
  275.    @endverbatim
  276.  *
  277.  *     You can combine sending and receiving in one object.
  278.  *
  279.    @verbatim
  280.      #include <kspeechsink.h>
  281.      class MyPart:
  282.          public KParts::ReadOnlyPart,
  283.          public KSpeech_stub,
  284.          virtual public KSpeechSink
  285.      {
  286.          protected:
  287.             ASYNC sentenceStarted(const QCString& appId, const uint jobNum, const uint seq);
  288.    @endverbatim
  289.  *
  290.  *     See below for the signals you can declare.
  291.  *
  292.  * 2.  In your class constructor, initialize DCOPObject with the name of your DCOP
  293.  *     receiving object.
  294.  *
  295.    @verbatim
  296.      MyPart::MyPart(QWidget *parent, const char *name) :
  297.          KParts::ReadOnlyPart(parent, name),
  298.          DCOPObject("mypart_kspeechsink") {
  299.    @endverbatim
  300.  *
  301.  *     Use any name you like.
  302.  *
  303.  * 3.  Where appropriate (usually in your constructor), make sure your DCOPClient
  304.  *     is registered and connect the %KTTSD DCOP signals to your declared receiving
  305.  *     methods.
  306.  *
  307.    @verbatim
  308.      // Register DCOP client.
  309.      DCOPClient *client = kapp->dcopClient();
  310.      if (!client->isRegistered())
  311.      {
  312.          client->attach();
  313.          client->registerAs(kapp->name());
  314.      }
  315.      // Connect KTTSD DCOP signals to our slots.
  316.      connectDCOPSignal("kttsd", "KSpeech",
  317.          "sentenceStarted(QCString,uint,uint)",
  318.          "sentenceStarted(QCString,uint,uint)",
  319.          false);
  320.    @endverbatim
  321.  *
  322.  *     Notice that the argument signatures differ slightly from the actual declarations.  For
  323.  *     example
  324.  *
  325.    @verbatim
  326.      ASYNC sentenceStarted(const QCString& appId, const uint jobNum, const uint seq);
  327.    @endverbatim
  328.  *
  329.  *     becomes
  330.  *
  331.    @verbatim
  332.        "sentenceStarted(QCString,uint,uint)",
  333.    @endverbatim
  334.  *
  335.  *     in the connectDCOPSignal call.
  336.  *
  337.  * 4.  Write the definition for the received signal.  Be sure to check whether the signal
  338.  *     is intended for your application.
  339.  *
  340.    @verbatim
  341.      ASYNC MyPart::sentenceStarted(const QCString& appId, const uint jobNum, const uint seq)
  342.      {
  343.          // Check appId to determine if this is our signal.
  344.          if (appId != dcopClient()->appId()) return;
  345.          // Do something here.
  346.      }
  347.    @endverbatim
  348.  *
  349.  * 5.  Add kspeechsink_DIR and kspeechsink.skel to your Makefile.am.  Example for an app
  350.  *     both sending and receiving.
  351.  *
  352.    @verbatim
  353.      kspeech_DIR = $(kde_includes)
  354.      kspeechsink_DIR = $(kde_includes)
  355.      libmypart_la_SOURCES = kspeech.stub kspeechsink.skel
  356.    @endverbatim
  357.  *
  358.  * @section talkers Talkers, Talker Codes, and Plugins
  359.  *
  360.  * Many of the methods permit you to specify a desired "talker".  This
  361.  * may be a simple language code, such as "en" for English, "es" for Spanish, etc.
  362.  * Code as NULL to use the default configured talker.
  363.  *
  364.  * Within KTTSMGR, the user has the ability to configure more than one talker for each language,
  365.  * with different voices, genders, volumes, and talking speeds.
  366.  *
  367.  * Talker codes serve two functions:
  368.  * - They identify configured plugins, and
  369.  * - They provide a way for applications to specify the desired speaking attributes
  370.  *   that influence the choice of plugin to speak text.
  371.  *
  372.  * A Talker Code consists of a series of XML tags and attributes.
  373.  * An example of a full Talker Code with all attributes specified is
  374.  * \code
  375.  *   <voice lang="en" name="kal" gender="male"/>
  376.  *   <prosody volume="soft" rate="fast"/>
  377.  *   <kttsd synthesizer="Festival" />
  378.  * \endcode
  379.  *
  380.  * (The @e voice and @e prosody tags are adapted from the W3C Speech Synthesis
  381.  * Markup Language (SSML) and Java Speech Markup Language (JSML).
  382.  * The @e kttsd tag is an extension to the SMML and JSML languages to support
  383.  * named synthesizers and text encodings.)
  384.  * %KTTS doesn't really care about the @e voice, @e prosody, and @e kttsd tags.  In fact,
  385.  * they may be omitted and just the attributes specified.  The example above then
  386.  * becomes
  387.  *
  388.  *   lang="en" name="kal" gender="male" volume="soft" rate="fast"
  389.  *   synthesizer="Festival"
  390.  *
  391.  * The attributes may be specified in any order.
  392.  *
  393.  * For clarity, the rest of the discussion
  394.  * will omit the @e voice, @e prosody, and @e kttsd tags.
  395.  *
  396.  * The attributes that make up a talker code are:
  397.  *
  398.  * - @e lang.         Language code and optional country code.
  399.  *                    Examples: en, es, en_US, en_GB. Codes
  400.  *                    are case in-sensitive and hyphen (-) or underscore (_) may be
  401.  *                    used to separate the country code from the language code.
  402.  * - @e synthesizer.  The name of the synthesizer (plugin) used to produce the speech.
  403.  * - @e gender.       May be either "male", "female", or "neutral".
  404.  * - @e name.         The name of the voice code.
  405.  *                    The choice of voice codes is synthesizer-specific.
  406.  * - @e volume.       May be "loud", "medium", or "quiet".  A synonym for "quiet" is
  407.  *                    "soft".
  408.  * - @e rate.         May be "fast", "medium", or "slow".
  409.  *
  410.  * Each plugin, once it has been configured by a user in kttsmgr, returns a
  411.  * fully-specified talker code to identify itself.  If the plugin supports it,
  412.  * the user may configure another instance of the plugin with a different set
  413.  * of attributes.  This is the difference between a "plugin" and a "talker".
  414.  * A talker is a configured instance of a plugin.  Each plugin (if it supports it)
  415.  * may be configured as multiple talkers.
  416.  *
  417.  * When the user configures %KTTSD, she configures one or more talkers and then
  418.  * places them in preferred order, top to bottom in kttsmgr.  In effect,
  419.  * she specifies her preferences for each of the talkers.
  420.  *
  421.  * When applications specify a talker code, they need not (and typically do not)
  422.  * give a full specification.  An example of a talker code with only some of the
  423.  * attributes specified might be
  424.  *
  425.  *   lang="en" gender="female"
  426.  *
  427.  * If the talker code is not in XML attribute format, it assumed to be a @e lang
  428.  * attribute.  So the talker code
  429.  *
  430.  *   en
  431.  *
  432.  * is interpreted as
  433.  *
  434.  *   lang="en"
  435.  *
  436.  * When a program requests a talker code in calls to setText, appendText,
  437.  * sayMessage, sayWarning, and sayScreenReaderOutput,
  438.  * %KTTSD tries to match the requested talker code to the closest matching
  439.  * configured talker.
  440.  *
  441.  * The @e lang attribute has highest priority (attempting to speak English with
  442.  * a Spanish synthesizer would likely be unintelligible).  So the language
  443.  * attribute is said to have "priority".
  444.  * If an application does not specify a language attribute, a default one will be assumed.
  445.  * The rest of the attributes are said to be "preferred".  If %KTTSD cannot find
  446.  * a talker with the exact preferred attributes requested, the closest matching
  447.  * talker will likely still be understandable.
  448.  *
  449.  * An application may specify that one or more of the attributes it gives in a talker
  450.  * code have priority by preceeding each priority attribute with an asterisk.
  451.  * For example, the following talker code
  452.  *
  453.  *  lang="en" gender="*female" volume="soft"
  454.  *
  455.  * means that the application wants to use a talker that supports American English language
  456.  * and Female gender.  If there is more than one such talker, one that supports
  457.  * Soft volume would be preferred.  Notice that a talker configured as English, Male,
  458.  * and Soft volume would not be picked as long as an English Female talker is
  459.  * available.
  460.  *
  461.  * The algorithm used by %KTTSD to find a matching talker is as follows:
  462.  *
  463.  * - If language code is not specified by the application, assume default configured
  464.  *   by user.  The primary language code automatically has priority.
  465.  * - (Note: This is not yet implemented.)
  466.  *   If there are no talkers configured in the language, %KTTSD will attempt
  467.  *   to automatically configure one (see automatic configuraton discussion below)
  468.  * - The talker that matches on the most priority attributes wins.
  469.  * - If a tie, the one that matches on the most preferred attributes wins.
  470.  * - If there is still a tie, the one nearest the top of the kttsmgr display
  471.  *   (first configured) will be chosen.
  472.  *
  473.  * Language codes actually consist of two parts, a language code and an optional
  474.  * country code.  For example, en_GB is English (United Kingdom).  The language code is
  475.  * treated as a priority attribute, but the country code (if specified) is treated
  476.  * as preferred.  So for example, if an application requests the following
  477.  * talker code
  478.  *
  479.  *   lang="en_GB" gender="male" volume="medium"
  480.  *
  481.  * then a talker configured as lang="en" gender="male" volume="medium" would be
  482.  * picked over one configured as lang="en_GB" gender="female" volume="soft",
  483.  * since the former matches on two preferred attributes and the latter only on the
  484.  * preferred attribute GB. An application can override this and make the country
  485.  * code priority with an asterisk.  For example,
  486.  *
  487.  *   lang="*en_GB" gender="male" volume="medium"
  488.  *
  489.  * To specify that American English is priority, put an asterisk in front of
  490.  * en_US, like this.
  491.  *
  492.  *   lang="*en_US" gender="male" volume="medium"
  493.  *
  494.  * Here the application is indicating that a talker that speaks American English
  495.  * has priorty over one that speaks a different form of English.
  496.  *
  497.  * (Note: Not yet implemented).
  498.  * If a language code is specified, and no plugin is currently configured
  499.  * with a matching language code, %KTTSD will attempt to automatically
  500.  * load and configure a plugin to support the requested language.  If
  501.  * there is no such plugin, or there is a plugin but it cannot automatically
  502.  * configure itself, %KTTSD will pick one of the configured plugins using the
  503.  * algorithm given above.
  504.  *
  505.  * Notice that %KTTSD will always pick a talker, even if it is a terrible match.
  506.  * (The principle is that something heard is better than nothing at all.  If
  507.  * it sounds terrible, user will change his configuration.)
  508.  * If an attribute is absolutely mandatory -- in other words the application
  509.  * must speak with the attribute or not at all -- the application can determine if
  510.  * there are any talkers configured with the attribute by calling getTalkers,
  511.  * and if there are none, display an error message to the user.
  512.  *
  513.  * Applications can implement their own talker-matching algorithm by
  514.  * calling getTalkers, then finding the desired talker from the returned
  515.  * list.  When the full talker code is passed in, %KKTSD will find an exact
  516.  * match and use the specified talker.
  517.  *
  518.  * If an application requires a configuration that user has not created,
  519.  * it should display a message to user instructing them to run kttsmgr and
  520.  * configure the desired talker.  (This must be done interactively because
  521.  * plugins often need user assistance locating voice files, etc.)
  522.  *
  523.  * The above scheme is designed to balance the needs
  524.  * of applications against user preferences.  Applications are given the control
  525.  * they @e might need, without unnecessarily burdening the application author.
  526.  * If you are an application author, the above discussion might seem overly
  527.  * complicated.  It isn't really all that complicated.  Here are rules of thumb:
  528.  *
  529.  *   - It is legitimate to give a NULL (0) talker code, in which case, the user's default
  530.  *     talker will be used.
  531.  *   - If you know the language code, give that in the talker code, otherwise
  532.  *     leave it out.
  533.  *   - If there is an attribute your application @e requires for proper functioning,
  534.  *     specify that with an asterisk in front of it.  For example, your app might
  535.  *     speak in two different voices, Male and Female.  (Since your
  536.  *     app requires both genders, call getTalkers to determine if both genders
  537.  *     are available, and if not, advise user to configure them.  Better yet,
  538.  *     give the user a choice of available distinquishing attributes
  539.  *     (loud/soft, fast/slow, etc.)
  540.  *   - If there are other attributes you would prefer, specify those without an
  541.  *     asterisk, but leave them out if it doesn't really make any difference
  542.  *     to proper functioning of your application.  Let the user decide them
  543.  *     when they configure %KTTS.
  544.  *
  545.  * One final note about talkers.  %KTTSD does talker matching for each sentence
  546.  * spoken, just before the sentence is sent to a plugin for synthesis.  Therefore,
  547.  * the user can change the effective talker in mid processing of a text job by
  548.  * changing his preferences, or even deleting or adding new talkers to the configuration.
  549.  *
  550.  * @section markup Speech Markup
  551.  *
  552.  * Note: %Speech Markup is not yet fully implemented in %KTTSD.
  553.  *
  554.  * Each of the five methods for queueing text to be spoken -- sayScreenReaderOutput,
  555.  * setText, appendText, sayMessage, and sayWarning -- may contain speech markup,
  556.  * provided that the plugin the user has configured supports that markup.  The markup
  557.  * languages and plugins currently supported are:
  558.  *
  559.  *   - %Speech Synthesis Markup language (SSML): Festival and Hadifix.
  560.  *
  561.  * This may change in the future as synthesizers improve.
  562.  *
  563.  * Before including markup in the text sent to kttsd, the application should
  564.  * query whether the currently-configured plugin
  565.  * supports the markup language by calling supportsMarkup.
  566.  *
  567.  * It it does not support the markup, it will be stripped out of the text.
  568.  *
  569.  * @section markers Support for Markers
  570.  *
  571.  * Note: Markers are not yet implemented in %KTTSD.
  572.  *
  573.  * When using a speech markup language, such as Sable, JSML, or SSML, the application may embed
  574.  * named markers into the text.  If the user's chosen speech plugin supports markers, %KTTSD
  575.  * will emit DCOP signal markerSeen when the speech engine encounters the marker.
  576.  * Depending upon the speech engine and plugin, this may occur either when the speech engine
  577.  * encounters the marker during synthesis from text to speech, or when the speech is actually
  578.  * spoken on the audio device.  The calling application can call the supportsMarkers
  579.  * method to determine if the currently configured plugin supports markers or not.
  580.  *
  581.  * @section sentenceparsing Sentence Parsing
  582.  *
  583.  * Not all speech engines provide robust capabilities for stopping synthesis that is in progress.
  584.  * To compensate for this, %KTTSD parses text jobs given to it by the setText and
  585.  * appendText methods into sentences and sends the sentences to the speech
  586.  * plugin one at a time.  In this way, should the user wish to stop the speech
  587.  * output, they can do so, and the worst that will happen is that the last sentence
  588.  * will be completed.  This is called Sentence Boundary Detection (SBD).
  589.  *
  590.  * Sentence Boundary Detection also permits the user to rewind by sentences.
  591.  *
  592.  * The default sentence delimiter used for plain text is as follows:
  593.  *
  594.  *   - A period (.), question mark (?), exclamation mark (!), colon (:), or
  595.  *     semi-colon (;) followed by whitespace (including newline), or
  596.  *   - Two newlines in a row separated by optional whitespace, or
  597.  *   - The end of the text.
  598.  *
  599.  * When given text containing speech markup, %KTTSD automatically determines the markup type
  600.  * and parses based on the sentence semantics of the markup language.
  601.  *
  602.  * An application may change the sentence delimiter by calling setSentenceDelimiter
  603.  * prior to calling setText.  Changing the delimiter does not affect other
  604.  * applications.
  605.  *
  606.  * Text given to %KTTSD via the sayWarning, sayMessage, and sayScreenReaderOutput
  607.  * methods is @e not parsed into sentences.  For this reason, applications
  608.  * should @e not send long messages with these methods.
  609.  *
  610.  * Sentence Boundary Detection is implemented as a plugin SBD filter.  See
  611.  * filters for more information.
  612.  *
  613.  * @section filters Filters
  614.  *
  615.  * Users may specify filters in the kttsmgr GUI.  Filters are plugins that modify the text
  616.  * to be spoken or change other characteristics of jobs.  Currently, the following filter plugins
  617.  * are available:
  618.  *
  619.  *   - String Replacer.  Permits users to substitute for mispoken words, or vocalize chat
  620.  *     emoticons.
  621.  *   - XML Transformer.  Given a particular XML or XHTML format, permits conversion of the
  622.  *     XML to SSML (Speech Synthesis Markup Language) using XSLT (XML Style Language - Transforms)
  623.  *     stylesheets.
  624.  *   - Talker Chooser.  Permits users to redirect jobs from one configured Talker to another
  625.  *     based on the contents of the job or application that sent it.
  626.  *
  627.  * Additional plugins may be available in the future.
  628.  *
  629.  * In additional to these regular filters, KTTS also implements Sentence Boundary Detection (SBD)
  630.  * as a plugin filter.  See sentenceparsing for more information.
  631.  *
  632.  * Regular filters are applied to Warnings, Messages, and Text jobs.  SBD filters are
  633.  * only applied to regular Text jobs; they are not applied to Warnings and Messages.  Screen
  634.  * Reader Outputs are never filtered.
  635.  *
  636.  * @section authors Authors
  637.  *
  638.  * @author Jos├⌐ Pablo Ezequiel "Pupeno" Fern├índez <pupeno@kde.org>
  639.  * @author Gary Cramblitt <garycramblitt@comcast.net>
  640.  * @author Olaf Schmidt <ojschmidt@kde.org>
  641.  * @author Gunnar Schmi Dt <gunnar@schmi-dt.de>
  642.  */
  643.  
  644. // NOTE: kspeech class is now obsolete.  Please use KSpeech instead.
  645.  
  646. class KSpeech : virtual public DCOPObject {
  647.     K_DCOP
  648.  
  649.     public:
  650.         /**
  651.         * @enum kttsdJobState
  652.         * Job states returned by method getTextJobState.
  653.         */
  654.         enum kttsdJobState
  655.         {
  656.             jsQueued = 0,                /**< Job has been queued but is not yet speakable. */
  657.             jsSpeakable = 1,             /**< Job is speakable, but is not speaking. */
  658.             jsSpeaking = 2,              /**< Job is currently speaking. */
  659.             jsPaused = 3,                /**< Job has been paused. */
  660.             jsFinished = 4               /**< Job is finished and is deleteable. */
  661.         };
  662.  
  663.         /**
  664.         * @enum kttsdMarkupType
  665.         * %Speech markup language types.
  666.         */
  667.         enum kttsdMarkupType
  668.         {
  669.             mtPlain = 0,                 /**< Plain text */
  670.             mtJsml = 1,                  /**< Java %Speech Markup Language */
  671.             mtSsml = 2,                  /**< %Speech Synthesis Markup Language */
  672.             mtSable = 3,                 /**< Sable 2.0 */
  673.             mtHtml = 4                   /**< HTML @since 3.5 */
  674.         };
  675.  
  676.     k_dcop:
  677.         /** @name DCOP Methods */
  678.         //@{
  679.  
  680.         /**
  681.         * Determine whether the currently-configured speech plugin supports a speech markup language.
  682.         * @param talker         Code for the talker to do the speaking.  Example "en".
  683.         *                       If NULL, defaults to the user's default talker.
  684.         * @param markupType     The kttsd code for the desired speech markup language.
  685.         * @return               True if the plugin currently configured for the indicated
  686.         *                       talker supports the indicated speech markup language.
  687.         * @see kttsdMarkupType
  688.         */
  689.         virtual bool supportsMarkup(const QString &talker, uint markupType = 0) const = 0;
  690.  
  691.         /**
  692.         * Determine whether the currently-configured speech plugin supports markers in speech markup.
  693.         * @param talker         Code for the talker to do the speaking.  Example "en".
  694.         *                       If NULL, defaults to the user's default talker.
  695.         * @return               True if the plugin currently configured for the indicated
  696.         *                       talker supports markers.
  697.         */
  698.         virtual bool supportsMarkers(const QString &talker) const = 0;
  699.  
  700.         /**
  701.         * Say a message as soon as possible, interrupting any other speech in progress.
  702.         * IMPORTANT: This method is reserved for use by Screen Readers and should not be used
  703.         * by any other applications.
  704.         * @param msg            The message to be spoken.
  705.         * @param talker         Code for the talker to do the speaking.  Example "en".
  706.         *                       If NULL, defaults to the user's default talker.
  707.         *                       If no plugin has been configured for the specified Talker code,
  708.         *                       defaults to the closest matching talker.
  709.         *
  710.         * If an existing Screen Reader output is in progress, it is stopped and discarded and
  711.         * replaced with this new message.
  712.         */
  713.         virtual ASYNC sayScreenReaderOutput(const QString &msg, const QString &talker) = 0;
  714.  
  715.         /**
  716.         * Say a warning.  The warning will be spoken when the current sentence
  717.         * stops speaking and takes precedence over Messages and regular text.  Warnings should only
  718.         * be used for high-priority messages requiring immediate user attention, such as
  719.         * "WARNING. CPU is overheating."
  720.         * @param warning        The warning to be spoken.
  721.         * @param talker         Code for the talker to do the speaking.  Example "en".
  722.         *                       If NULL, defaults to the user's default talker.
  723.         *                       If no plugin has been configured for the specified Talker code,
  724.         *                       defaults to the closest matching talker.
  725.         */
  726.         virtual ASYNC sayWarning(const QString &warning, const QString &talker) = 0;
  727.  
  728.         /**
  729.         * Say a message.  The message will be spoken when the current sentence stops speaking
  730.         * but after any warnings have been spoken.
  731.         * Messages should be used for one-shot messages that can't wait for
  732.         * normal text messages to stop speaking, such as "You have mail.".
  733.         * @param message        The message to be spoken.
  734.         * @param talker         Code for the talker to do the speaking.  Example "en".
  735.         *                       If NULL, defaults to the user's default talker.
  736.         *                       If no talker has been configured for the specified talker code,
  737.         *                       defaults to the closest matching talker.
  738.         */
  739.         virtual ASYNC sayMessage(const QString &message, const QString &talker) = 0;
  740.  
  741.         /**
  742.         * Sets the GREP pattern that will be used as the sentence delimiter.
  743.         * @param delimiter      A valid GREP pattern.
  744.         *
  745.         * The default sentence delimiter is
  746.           @verbatim
  747.               ([\\.\\?\\!\\:\\;])(\\s|$|(\\n *\\n))
  748.           @endverbatim
  749.         *
  750.         * Note that backward slashes must be escaped.
  751.         * When %KTTSD parses the text, it replaces all tabs, spaces, and formfeeds
  752.         * with a single space, and then replaces the sentence delimiters using
  753.         * the following statement:
  754.           @verbatim
  755.               QString::replace(sentenceDelimiter, "\\1\t");
  756.           @endverbatim
  757.         *
  758.         * which replaces all sentence delimiters with a tab, but
  759.         * preserving the first capture text (first parenthesis).  In other
  760.         * words, the sentence punctuation is preserved.
  761.         * The tab is later used to separate the text into sentences.
  762.         *
  763.         * Changing the sentence delimiter does not affect other applications.
  764.         *
  765.         * @see sentenceparsing
  766.         */
  767.         virtual ASYNC setSentenceDelimiter(const QString &delimiter) = 0;
  768.  
  769.         /**
  770.         * Queue a text job.  Does not start speaking the text.
  771.         * @param text           The message to be spoken.
  772.         * @param talker         Code for the talker to do the speaking.  Example "en".
  773.         *                       If NULL, defaults to the user's default plugin.
  774.         *                       If no plugin has been configured for the specified Talker code,
  775.         *                       defaults to the closest matching talker.
  776.         * @return               Job number.
  777.         *
  778.         * Plain text is parsed into individual sentences using the current sentence delimiter.
  779.         * Call setSentenceDelimiter to change the sentence delimiter prior to
  780.         * calling setText.
  781.         * Call getTextCount to retrieve the sentence count after calling setText.
  782.         *
  783.         * The text may contain speech mark language, such as Sable, JSML, or SSML,
  784.         * provided that the speech plugin/engine support it.  In this case,
  785.         * sentence parsing follows the semantics of the markup language.
  786.         *
  787.         * Call startText to mark the job as speakable and if the
  788.         * job is the first speakable job in the queue, speaking will begin.
  789.         *
  790.         * @see getTextCount
  791.         * @see startText
  792.         */
  793.         virtual uint setText(const QString &text, const QString &talker) = 0;
  794.  
  795.         /**
  796.         * Say a plain text job.  This is a convenience method that
  797.         * combines setText and startText into a single call.
  798.         * @param text           The message to be spoken.
  799.         * @param talker         Code for the talker to do the speaking.  Example "en".
  800.         *                       If NULL, defaults to the user's default plugin.
  801.         *                       If no plugin has been configured for the specified Talker code,
  802.         *                       defaults to the closest matching talker.
  803.         * @return               Job number.
  804.         *
  805.         * Plain text is parsed into individual sentences using the current sentence delimiter.
  806.         * Call setSentenceDelimiter to change the sentence delimiter prior to
  807.         * calling setText.
  808.         * Call getTextCount to retrieve the sentence count after calling setText.
  809.         *
  810.         * The text may contain speech mark language, such as Sable, JSML, or SSML,
  811.         * provided that the speech plugin/engine support it.  In this case,
  812.         * sentence parsing follows the semantics of the markup language.
  813.         *
  814.         * The job is marked speakable.
  815.         * If there are other speakable jobs preceeding this one in the queue,
  816.         * those jobs continue speaking and when finished, this job will begin speaking.
  817.         * If there are no other speakable jobs preceeding this one, it begins speaking.
  818.         *
  819.         * @see getTextCount
  820.         *
  821.         * @since KDE 3.5
  822.         */
  823.         virtual uint sayText(const QString &text, const QString &talker) = 0;
  824.  
  825.         /**
  826.         * Adds another part to a text job.  Does not start speaking the text.
  827.         * @param text           The message to be spoken.
  828.         * @param jobNum         Job number of the text job.
  829.         *                       If zero, applies to the last job queued by the application,
  830.         *                       but if no such job, applies to the current job (if any).
  831.         * @return               Part number for the added part.  Parts are numbered starting at 1.
  832.         *
  833.         * The text is parsed into individual sentences.  Call getTextCount to retrieve
  834.         * the sentence count.  Call startText to mark the job as speakable and if the
  835.         * job is the first speakable job in the queue, speaking will begin.
  836.         *
  837.         * @see setText.
  838.         * @see startText.
  839.         */
  840.         virtual int appendText(const QString &text, uint jobNum=0) = 0;
  841.  
  842.         /**
  843.         * Queue a text job from the contents of a file.  Does not start speaking the text.
  844.         * @param filename       Full path to the file to be spoken.  May be a URL.
  845.         * @param talker         Code for the talker to do the speaking.  Example "en".
  846.         *                       If NULL, defaults to the user's default talker.
  847.         *                       If no plugin has been configured for the specified Talker code,
  848.         *                       defaults to the closest matching talker.
  849.         * @param encoding       Name of the encoding to use when reading the file.  If
  850.         *                       NULL or Empty, uses default stream encoding.
  851.         * @return               Job number.  0 if an error occurs.
  852.         *
  853.         * Plain text is parsed into individual sentences using the current sentence delimiter.
  854.         * Call setSentenceDelimiter to change the sentence delimiter prior to calling setText.
  855.         * Call getTextCount to retrieve the sentence count after calling setText.
  856.         *
  857.         * The text may contain speech mark language, such as Sable, JSML, or SSML,
  858.         * provided that the speech plugin/engine support it.  In this case,
  859.         * sentence parsing follows the semantics of the markup language.
  860.         *
  861.         * Call startText to mark the job as speakable and if the
  862.         * job is the first speakable job in the queue, speaking will begin.
  863.         *
  864.         * @see getTextCount
  865.         * @see startText
  866.         */
  867.         virtual uint setFile(const QString &filename, const QString &talker,
  868.             const QString& encoding) = 0;
  869.  
  870.         /**
  871.         * Get the number of sentences in a text job.
  872.         * @param jobNum         Job number of the text job.
  873.         *                       If zero, applies to the last job queued by the application,
  874.         *                       but if no such job, applies to the current job (if any).
  875.         * @return               The number of sentences in the job.  -1 if no such job.
  876.         *
  877.         * The sentences of a job are given sequence numbers from 1 to the number returned by this
  878.         * method.  The sequence numbers are emitted in the sentenceStarted and
  879.         * sentenceFinished signals.
  880.         */
  881.         virtual int getTextCount(uint jobNum=0) = 0;
  882.  
  883.         /**
  884.         * Get the job number of the current text job.
  885.         * @return               Job number of the current text job. 0 if no jobs.
  886.         *
  887.         * Note that the current job may not be speaking. See isSpeakingText.
  888.         *
  889.         * @see getTextJobState.
  890.         * @see isSpeakingText
  891.         */
  892.         virtual uint getCurrentTextJob() = 0;
  893.  
  894.         /**
  895.         * Get the number of jobs in the text job queue.
  896.         * @return               Number of text jobs in the queue.  0 if none.
  897.         */
  898.         virtual uint getTextJobCount() = 0;
  899.  
  900.         /**
  901.         * Get a comma-separated list of text job numbers in the queue.
  902.         * @return               Comma-separated list of text job numbers in the queue.
  903.         */
  904.         virtual QString getTextJobNumbers() = 0;
  905.  
  906.         /**
  907.         * Get the state of a text job.
  908.         * @param jobNum         Job number of the text job.
  909.         *                       If zero, applies to the last job queued by the application,
  910.         *                       but if no such job, applies to the current job (if any).
  911.         * @return               State of the job. -1 if invalid job number.
  912.         *
  913.         * @see kttsdJobState
  914.         */
  915.         virtual int getTextJobState(uint jobNum=0) = 0;
  916.  
  917.         /**
  918.         * Get information about a text job.
  919.         * @param jobNum         Job number of the text job.
  920.         *                       If zero, applies to the last job queued by the application,
  921.         *                       but if no such job, applies to the current job (if any).
  922.         * @return               A QDataStream containing information about the job.
  923.         *                       Blank if no such job.
  924.         *
  925.         * The stream contains the following elements:
  926.         *   - int state        - Job state.
  927.         *   - QCString appId   - DCOP senderId of the application that requested the speech job.
  928.         *   - QString talker   - Talker Code requested by application.
  929.         *   - int seq          - Current sentence being spoken.  Sentences are numbered starting at 1.
  930.         *   - int sentenceCount - Total number of sentences in the job.
  931.         *   - int partNum      - Current part of the job begin spoken.  Parts are numbered starting at 1.
  932.         *   - int partCount    - Total number of parts in the job.
  933.         *
  934.         * Note that sequence numbers apply to the entire job.  They do not start from 1 at the beginning of
  935.         * each part.
  936.         *
  937.         * The following sample code will decode the stream:
  938.                 @code
  939.                     QByteArray jobInfo = getTextJobInfo(jobNum);
  940.                     QDataStream stream(jobInfo, IO_ReadOnly);
  941.                     int state;
  942.                     QCString appId;
  943.                     QString talker;
  944.                     int seq;
  945.                     int sentenceCount;
  946.                     int partNum;
  947.                     int partCount;
  948.                     stream >> state;
  949.                     stream >> appId;
  950.                     stream >> talker;
  951.                     stream >> seq;
  952.                     stream >> sentenceCount;
  953.                     stream >> partNum;
  954.                     stream >> partCount;
  955.                 @endcode
  956.          */
  957.         virtual QByteArray getTextJobInfo(uint jobNum=0) = 0;
  958.  
  959.         /**
  960.         * Given a Talker Code, returns the Talker ID of the talker that would speak
  961.         * a text job with that Talker Code.
  962.         * @param talkerCode     Talker Code.
  963.         * @return               Talker ID of the talker that would speak the text job.
  964.         */
  965.         virtual QString talkerCodeToTalkerId(const QString& talkerCode) = 0;
  966.  
  967.         /**
  968.         * Return a sentence of a job.
  969.         * @param jobNum         Job number of the text job.
  970.         *                       If zero, applies to the last job queued by the application,
  971.         *                       but if no such job, applies to the current job (if any).
  972.         * @param seq            Sequence number of the sentence.
  973.         * @return               The specified sentence in the specified job.  If no such
  974.         *                       job or sentence, returns "".
  975.         */
  976.         virtual QString getTextJobSentence(uint jobNum=0, uint seq=0) = 0;
  977.  
  978.         /**
  979.         * Determine if kttsd is currently speaking any text jobs.
  980.         * @return               True if currently speaking any text jobs.
  981.         */
  982.         virtual bool isSpeakingText() const = 0;
  983.  
  984.         /**
  985.         * Remove a text job from the queue.
  986.         * @param jobNum         Job number of the text job.
  987.         *                       If zero, applies to the last job queued by the application,
  988.         *                       but if no such job, applies to the current job (if any).
  989.         *
  990.         * The job is deleted from the queue and the textRemoved signal is emitted.
  991.         *
  992.         * If there is another job in the text queue, and it is marked speakable,
  993.         * that job begins speaking.
  994.         */
  995.         virtual ASYNC removeText(uint jobNum=0) = 0;
  996.  
  997.         /**
  998.         * Start a text job at the beginning.
  999.         * @param jobNum         Job number of the text job.
  1000.         *                       If zero, applies to the last job queued by the application,
  1001.         *                       but if no such job, applies to the current job (if any).
  1002.         *
  1003.         * Rewinds the job to the beginning.
  1004.         *
  1005.         * The job is marked speakable.
  1006.         * If there are other speakable jobs preceeding this one in the queue,
  1007.         * those jobs continue speaking and when finished, this job will begin speaking.
  1008.         * If there are no other speakable jobs preceeding this one, it begins speaking.
  1009.         *
  1010.         * The textStarted signal is emitted when the text job begins speaking.
  1011.         * When all the sentences of the job have been spoken, the job is marked for deletion from
  1012.         * the text queue and the textFinished signal is emitted.
  1013.         */
  1014.         virtual ASYNC startText(uint jobNum=0) = 0;
  1015.  
  1016.         /**
  1017.         * Stop a text job and rewind to the beginning.
  1018.         * @param jobNum         Job number of the text job.
  1019.         *                       If zero, applies to the last job queued by the application,
  1020.         *                       but if no such job, applies to the current job (if any).
  1021.         *
  1022.         * The job is marked not speakable and will not be speakable until startText
  1023.         * or resumeText is called.
  1024.         *
  1025.         * If there are speaking jobs preceeding this one in the queue, they continue speaking.
  1026.         *
  1027.         * If the job is currently speaking, the textStopped signal is emitted,
  1028.         * the job stops speaking, and if the next job in the queue is speakable, it
  1029.         * begins speaking.
  1030.         *
  1031.         * Depending upon the speech engine and plugin used, speech may not stop immediately
  1032.         * (it might finish the current sentence).
  1033.         */
  1034.         virtual ASYNC stopText(uint jobNum=0) = 0;
  1035.  
  1036.         /**
  1037.         * Pause a text job.
  1038.         * @param jobNum         Job number of the text job.
  1039.         *                       If zero, applies to the last job queued by the application,
  1040.         *                       but if no such job, applies to the current job (if any).
  1041.         *
  1042.         * The job is marked as paused and will not be speakable until resumeText or
  1043.         * startText is called.
  1044.         *
  1045.         * If there are speaking jobs preceeding this one in the queue, they continue speaking.
  1046.         *
  1047.         * If the job is currently speaking, the textPaused signal is emitted and the job
  1048.         * stops speaking.  Note that if the next job in the queue is speakable, it does
  1049.         * not start speaking as long as this job is paused.
  1050.         *
  1051.         * Depending upon the speech engine and plugin used, speech may not stop immediately
  1052.         * (it might finish the current sentence).
  1053.         *
  1054.         * @see resumeText
  1055.         */
  1056.         virtual ASYNC pauseText(uint jobNum=0) = 0;
  1057.  
  1058.         /**
  1059.         * Start or resume a text job where it was paused.
  1060.         * @param jobNum         Job number of the text job.
  1061.         *                       If zero, applies to the last job queued by the application,
  1062.         *                       but if no such job, applies to the current job (if any).
  1063.         *
  1064.         * The job is marked speakable.
  1065.         *
  1066.         * If the job is currently speaking, or is waiting to be spoken (speakable
  1067.         * state), the resumeText() call is ignored.
  1068.         *
  1069.         * If the job is currently queued, or is finished, it is the same as calling
  1070.         * @see startText .
  1071.         *
  1072.         * If there are speaking jobs preceeding this one in the queue,
  1073.         * those jobs continue speaking and when finished this job will begin
  1074.         * speaking where it left off.
  1075.         *
  1076.         * The textResumed signal is emitted when the job resumes.
  1077.         *
  1078.         * @see pauseText
  1079.         */
  1080.         virtual ASYNC resumeText(uint jobNum=0) = 0;
  1081.  
  1082.         /**
  1083.         * Get a list of the talkers configured in KTTS.
  1084.         * @return               A QStringList of fully-specified talker codes, one
  1085.         *                       for each talker user has configured.
  1086.         *
  1087.         * @see talkers
  1088.         */
  1089.         virtual QStringList getTalkers() = 0;
  1090.  
  1091.         /**
  1092.         * Change the talker for a text job.
  1093.         * @param jobNum         Job number of the text job.
  1094.         *                       If zero, applies to the last job queued by the application,
  1095.         *                       but if no such job, applies to the current job (if any).
  1096.         * @param talker         New code for the talker to do the speaking.  Example "en".
  1097.         *                       If NULL, defaults to the user's default talker.
  1098.         *                       If no plugin has been configured for the specified Talker code,
  1099.         *                       defaults to the closest matching talker.
  1100.         */
  1101.         virtual ASYNC changeTextTalker(const QString &talker, uint jobNum=0 ) = 0;
  1102.  
  1103.         /**
  1104.         * Get the user's default talker.
  1105.         * @return               A fully-specified talker code.
  1106.         *
  1107.         * @see talkers
  1108.         * @see getTalkers
  1109.         */
  1110.         virtual QString userDefaultTalker() = 0;
  1111.  
  1112.         /**
  1113.         * Move a text job down in the queue so that it is spoken later.
  1114.         * @param jobNum         Job number of the text job.
  1115.         *                       If zero, applies to the last job queued by the application,
  1116.         *                       but if no such job, applies to the current job (if any).
  1117.         *
  1118.         * If the job is currently speaking, it is paused.
  1119.         * If the next job in the queue is speakable, it begins speaking.
  1120.         */
  1121.         virtual ASYNC moveTextLater(uint jobNum=0) = 0;
  1122.  
  1123.         /**
  1124.         * Jump to the first sentence of a specified part of a text job.
  1125.         * @param partNum        Part number of the part to jump to.  Parts are numbered starting at 1.
  1126.         * @param jobNum         Job number of the text job.
  1127.         *                       If zero, applies to the last job queued by the application,
  1128.         *                       but if no such job, applies to the current job (if any).
  1129.         * @return               Part number of the part actually jumped to.
  1130.         *
  1131.         * If partNum is greater than the number of parts in the job, jumps to last part.
  1132.         * If partNum is 0, does nothing and returns the current part number.
  1133.         * If no such job, does nothing and returns 0.
  1134.         * Does not affect the current speaking/not-speaking state of the job.
  1135.         */
  1136.         virtual int jumpToTextPart(int partNum, uint jobNum=0) = 0;
  1137.  
  1138.         /**
  1139.         * Advance or rewind N sentences in a text job.
  1140.         * @param n              Number of sentences to advance (positive) or rewind (negative) in the job.
  1141.         * @param jobNum         Job number of the text job.
  1142.         *                       If zero, applies to the last job queued by the application,
  1143.         *                       but if no such job, applies to the current job (if any).
  1144.         * @return               Sequence number of the sentence actually moved to.  Sequence numbers
  1145.         *                       are numbered starting at 1.
  1146.         *
  1147.         * If no such job, does nothing and returns 0.
  1148.         * If n is zero, returns the current sequence number of the job.
  1149.         * Does not affect the current speaking/not-speaking state of the job.
  1150.         */
  1151.         virtual uint moveRelTextSentence(int n, uint jobNum=0) = 0;
  1152.  
  1153.         /**
  1154.         * Add the clipboard contents to the text queue and begin speaking it.
  1155.         */
  1156.         virtual ASYNC speakClipboard() = 0;
  1157.  
  1158.         /**
  1159.         * Displays the %KTTS Manager dialog.  In this dialog, the user may backup or skip forward in
  1160.         * any text job by sentence or part, rewind jobs, pause or resume jobs, or
  1161.         * delete jobs.
  1162.         */
  1163.         virtual void showDialog() = 0;
  1164.  
  1165.         /**
  1166.         * Stop the service.
  1167.         */
  1168.         virtual void kttsdExit() = 0;
  1169.  
  1170.         /**
  1171.         * Re-start %KTTSD.
  1172.         */
  1173.         virtual void reinit() = 0;
  1174.  
  1175.         /**
  1176.         * Return the KTTSD deamon version number.
  1177.         * @since KDE 3.5
  1178.         */
  1179.         virtual QString version() = 0;
  1180.         //@}
  1181.  
  1182.     k_dcop_signals:
  1183.         void ignoreThis();
  1184.  
  1185.         /** @name DCOP Signals */
  1186.         //@{
  1187.  
  1188.         /**
  1189.         * This signal is emitted when KTTSD starts or restarts after a call to reinit.
  1190.         */
  1191.         void kttsdStarted();
  1192.         /**
  1193.         * This signal is emitted just before KTTSD exits.
  1194.         */
  1195.         void kttsdExiting();
  1196.         /**
  1197.         * This signal is emitted when the speech engine/plugin encounters a marker in the text.
  1198.         * @param appId          DCOP application ID of the application that queued the text.
  1199.         * @param markerName     The name of the marker seen.
  1200.         *
  1201.         * @see markers
  1202.         */
  1203.         void markerSeen(const QCString& appId, const QString& markerName);
  1204.         /**
  1205.         * This signal is emitted whenever a sentence begins speaking.
  1206.         * @param appId          DCOP application ID of the application that queued the text.
  1207.         * @param jobNum         Job number of the text job.
  1208.         * @param seq            Sequence number of the text.
  1209.         *
  1210.         * @see getTextCount
  1211.         */
  1212.         void sentenceStarted(const QCString& appId, uint jobNum, uint seq);
  1213.         /**
  1214.         * This signal is emitted when a sentence has finished speaking.
  1215.         * @param appId          DCOP application ID of the application that queued the text.
  1216.         * @param jobNum         Job number of the text job.
  1217.         * @param seq            Sequence number of the text.
  1218.         *
  1219.         * @see getTextCount
  1220.         */
  1221.         void sentenceFinished(const QCString& appId, uint jobNum, uint seq);
  1222.  
  1223.         /**
  1224.         * This signal is emitted whenever a new text job is added to the queue.
  1225.         * @param appId          The DCOP senderId of the application that created the job.
  1226.         * @param jobNum         Job number of the text job.
  1227.         */
  1228.         void textSet(const QCString& appId, uint jobNum);
  1229.  
  1230.         /**
  1231.         * This signal is emitted whenever a new part is appended to a text job.
  1232.         * @param appId          The DCOP senderId of the application that created the job.
  1233.         * @param jobNum         Job number of the text job.
  1234.         * @param partNum        Part number of the new part.  Parts are numbered starting
  1235.         *                       at 1.
  1236.         */
  1237.         void textAppended(const QCString& appId, uint jobNum, int partNum);
  1238.  
  1239.         /**
  1240.         * This signal is emitted whenever speaking of a text job begins.
  1241.         * @param appId          The DCOP senderId of the application that created the job.
  1242.         * @param jobNum         Job number of the text job.
  1243.         */
  1244.         void textStarted(const QCString& appId, uint jobNum);
  1245.         /**
  1246.         * This signal is emitted whenever a text job is finished.  The job has
  1247.         * been marked for deletion from the queue and will be deleted when another
  1248.         * job reaches the Finished state. (Only one job in the text queue may be
  1249.         * in state Finished at one time.)  If startText or resumeText is
  1250.         * called before the job is deleted, it will remain in the queue for speaking.
  1251.         * @param appId          The DCOP senderId of the application that created the job.
  1252.         * @param jobNum         Job number of the text job.
  1253.         */
  1254.         void textFinished(const QCString& appId, uint jobNum);
  1255.         /**
  1256.         * This signal is emitted whenever a speaking text job stops speaking.
  1257.         * @param appId          The DCOP senderId of the application that created the job.
  1258.         * @param jobNum         Job number of the text job.
  1259.         *
  1260.         * The signal is only emitted if stopText() is called and the job is currently
  1261.         * speaking.
  1262.         */
  1263.         void textStopped(const QCString& appId, uint jobNum);
  1264.         /**
  1265.         * This signal is emitted whenever a speaking text job is paused.
  1266.         * @param appId          The DCOP senderId of the application that created the job.
  1267.         * @param jobNum         Job number of the text job.
  1268.         */
  1269.         void textPaused(const QCString& appId, uint jobNum);
  1270.         /**
  1271.         * This signal is emitted when a text job, that was previously paused, resumes speaking.
  1272.         * @param appId          The DCOP senderId of the application that created the job.
  1273.         * @param jobNum         Job number of the text job.
  1274.         */
  1275.         void textResumed(const QCString& appId, uint jobNum);
  1276.         /**
  1277.         * This signal is emitted whenever a text job is deleted from the queue.
  1278.         * The job is no longer in the queue when this signal is emitted.
  1279.         * @param appId          The DCOP senderId of the application that created the job.
  1280.         * @param jobNum         Job number of the text job.
  1281.         */
  1282.         void textRemoved(const QCString& appId, uint jobNum);
  1283.         //@}
  1284. };
  1285.  
  1286. #endif // _KSPEECH_H_
  1287.