kutils: new kspeech library to replace the kttsd service and its interface

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-09-29 15:01:16 +03:00
parent 6ea85df1c2
commit d47d62e503
19 changed files with 345 additions and 1167 deletions

View file

@ -263,6 +263,14 @@ set_package_properties(Libmicrohttpd PROPERTIES
PURPOSE "HTTP(S) server"
)
macro_optional_find_package(Speechd)
set_package_properties(Speechd PROPERTIES
DESCRIPTION "Speech Dispatcher provides a high-level device independent layer for speech synthesis"
URL "http://www.freebsoft.org/speechd"
TYPE RECOMMENDED
PURPOSE "Text To Speech"
)
################# configure checks and create the configured files #################
include(ConfigureChecks.cmake)

View file

@ -62,6 +62,7 @@
# KDE4_KPOWERMANAGER_LIBS - the kpowermanager library and all depending libraries
# KDE4_KDNSSD_LIBS - the kdnssd library and all depending libraries
# KDE4_KHTTP_LIBS - the khttp library and all depending libraries
# KDE4_KSPEECH_LIBS - the kspeech library and all depending libraries
#
# The variable INSTALL_TARGETS_DEFAULT_ARGS can be used when installing libraries
# or executables into the default locations.
@ -245,6 +246,7 @@ set(_kde_libraries
kpowermanager
kdnssd
khttp
kspeech
kfile
kidletime
kio

View file

@ -5,7 +5,6 @@ project(interfaces)
add_subdirectory( ktexteditor )
add_subdirectory( kregexpeditor )
add_subdirectory( terminal )
add_subdirectory( kspeech )
########### install files ###############

View file

@ -1,23 +0,0 @@
# dummy library for generate_export_header()
add_library(kspeech kspeech_dummy.cpp)
generate_export_header(kspeech)
install(
FILES
dbustexttospeech.desktop
DESTINATION ${KDE4_SERVICETYPES_INSTALL_DIR}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/kspeech_export.h
kspeech.h
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}
)
install(
FILES
org.kde.KSpeech.xml
DESTINATION ${KDE4_DBUS_INTERFACES_INSTALL_DIR}
)

View file

@ -1,89 +0,0 @@
[Desktop Entry]
Type=ServiceType
X-KDE-ServiceType=DBUS/Text-to-Speech
Comment=Text-to-Speech Service with a D-Bus interface
Comment[ar]=خدمة قراءة النص مع واجهة D-Bus
Comment[as]= D-Bus িি- - ি
Comment[ast]=Serviciu Testu Faláu con interfaz D-Bus
Comment[be]=Сервіс агалошвання тэксту з інтэрфейсам D-Bus
Comment[be@latin]=Słužba ahałašeńnia tekstu z interfejsam D-Bus
Comment[bg]=Синтез на глас с интерфейс DCOP
Comment[bn]=ি- (DBUS) -- ি
Comment[bn_IN]=D-Bus -- ি
Comment[bs]=Tekstugovor servis sa dbus sučeljem
Comment[ca]=Servei de síntesi de veu amb una interfície D-Bus
Comment[ca@valencia]=Servei de síntesi de veu amb una interfície D-Bus
Comment[cs]=Služba text-na-řeč s DBUS rozhraním
Comment[csb]=Ùsłëżnota czëtaniô tekstu z interfejsã DCOP
Comment[da]=Tekst-til-tale-tjeneste med B-BUS-grænseflade
Comment[de]=Sprachausgabe mit D-Bus-Schnittstelle
Comment[el]=Υπηρεσία κειμένου-σε-ομιλία με διεπαφή D-Bus
Comment[en_GB]=Text-to-Speech Service with a D-Bus interface
Comment[eo]=Teksto-al-voĉa servo kun D-Bus-interfaco
Comment[es]=Servicio de texto a voz con una interfaz D-Bus
Comment[et]=Teksti ettelugemise teenus D-Bus-liidesega
Comment[eu]=Testua-ahoskatzea zerbitzua D-Bus interfazearekin
Comment[fa]=خدمت متن به گفتار با یک واسط D-Bus
Comment[fi]=Puhesynteesipalvelu D-Bus-rajapinnalla
Comment[fr]=Service de synthèse vocale avec une interface D-Bus
Comment[fy]=Tekst-ta-prate mei in D-Bus-ynterface
Comment[ga]=Seirbhís Téacs-go-Caint le comhéadan D-Bus
Comment[gl]=Servizo de texto-para-fala con interface D-Bus
Comment[gu]=D-Bus --િ
Comment[he]=שירות טקסט לדיבור עם ממשק D-Bus
Comment[hi]=- --
Comment[hne]=- --
Comment[hr]=Usluga tekst-u-govor s D-Bus sučeljem.
Comment[hsb]=konwertowanje teksta na rěč z D-Bus-interfejsom
Comment[hu]=Szövegfelolvasó szolgáltatás D-Bus felülettel
Comment[hy]=Տեքստը խոսք դարձնելու ծառայություն D-Bus ծրագրերի համակարգով
Comment[ia]=Servicio de texto a parola con un interfacie D-Bus
Comment[id]=Layanan Teks-ke-Percakapan dengan antarmuka D-Bus
Comment[is]=Texti-í-tal þjónusta með D-Bus viðmóti
Comment[it]=Servizio di pronuncia con un'interfaccia D-Bus
Comment[ja]=D-Bus
Comment[kk]=D-Bus интерфейсті мәтіннен дыбыстап оқу қызметі
Comment[km]=-- DCOP
Comment[kn]=D-Bus ಿ (interface) (text-to-speech)
Comment[ko]=D-Bus
Comment[ku]=Servîsa Axaftin-bi-Nivîsê bi navrû ya D-Bus
Comment[lt]=Teksto vertimo kalba tarnyba su D-Bus sąsaja
Comment[lv]=Teksts-uz-runu serviss ar D-Bus saskarni
Comment[mai]=- --
Comment[mk]=Сервис за текст-во-говор со D-Bus-интерфејс
Comment[ml]=ി- ിി ി
Comment[mr]=D-Bus
Comment[ms]=Servis Teks-ke-Tutur dengan antaramuka D-Bus
Comment[nb]=Tekst til tale-program med D-Bus-grensesnitt
Comment[nds]=Vörleesdeenst mit en D-BUS-Koppelsteed
Comment[ne]=D-Bus --
Comment[nl]=Tekst-tot-spraak-dienst met een DCOP interface
Comment[nn]=Tekst-til-tale-teneste med D-Bus-grensesnitt
Comment[or]=Text-to-Speech Service with a D-Bus interface
Comment[pa]= D-Bus -- ਿ
Comment[pl]=Usługa czytania tekstu z interfejsem D-Bus
Comment[pt]=Serviço de Texto-para-Fala com interface D-Bus
Comment[pt_BR]=Serviço de conversão de texto-em-fala com interface D-Bus
Comment[ro]=Serviciu text-vorbire cu interfață D-Bus
Comment[ru]=Служба синтеза речи с интерфейсом D-Bus
Comment[se]=Hubmon-teaksta-bálvalus mas lea D-Bus-lákta
Comment[sk]=Služba prevodu textu na reč s rozhraním D-Bus
Comment[sl]=Storitev besedilo-v-govor z vmesnikom D-Bus
Comment[sr]=Текстуговор сервис са дбус сучељем
Comment[sr@ijekavian]=Текстуговор сервис са дбус сучељем
Comment[sr@ijekavianlatin]=Tekstugovor servis sa DBus sučeljem
Comment[sr@latin]=Tekstugovor servis sa DBus sučeljem
Comment[sv]=Text-till-tal-tjänst med ett D-bus-gränssnitt
Comment[ta]=D-Bus ி -ி
Comment[te]=ి- ి ి
Comment[tg]=Хидмати Мант-ба-Талаффуз бо интерфейси D-Bus
Comment[th]= DCOP
Comment[tr]=D-Bus Arayüzü Kullanan Metin Seslendirme Servisi
Comment[tt]=D-Bus интерфейсы аша эшләуче Текст Укучы Хезмәте
Comment[ug]=D-Bus ئېغىزى بار تېكىستتىن ئاۋازغا مۇلازىمىتى
Comment[uk]=Служба синтезу мовлення з інтерфейсом D-Bus
Comment[vi]=Dch v Văn bn sang Tiếng nói có giao din D-Bus
Comment[wa]=Siervice tecse-viè-vwès avou ene eterface D-Bus
Comment[x-test]=xxText-to-Speech Service with a D-Bus interfacexx
Comment[zh_CN]= D-Bus
Comment[zh_TW]=DBUS

View file

@ -1,735 +0,0 @@
/***************************************************** vim:set ts=4 sw=4 sts=4:
KSpeech
The KDE Text-to-Speech API.
------------------------------
Copyright:
(C) 2006 by Gary Cramblitt <garycramblitt@comcast.net>
(C) 2009 by Jeremy Whiting <jpwhiting@kde.org>
-------------------
Original author: Gary Cramblitt <garycramblitt@comcast.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef KSPEECH_H
#define KSPEECH_H
#include "kspeech_export.h"
// Qt includes
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QByteArray>
class KSpeechPrivate;
/**
* KSpeech -- the KDE Text-to-Speech API.
*
* Note: Applications do not use this class directly. Instead,
* use the @ref KSpeechInterface object as described in
* @ref programming.
*
* See also @ref kspeech_intro
*/
class KSPEECH_EXPORT KSpeech : public QObject
{
Q_OBJECT
public:
/**
* @enum JobPriority
* Determines the priority of jobs submitted by @ref say.
* maps directly to SPDPriority
*/
enum JobPriority
{
jpAll = 0, /**< All priorities. Used for information retrieval only. */
jpScreenReaderOutput = 1, /**< Screen Reader job. SPD_IMPORTANT */
jpWarning = 2, /**< Warning job. SPD_NOTIFICATION */
jpMessage = 3, /**< Message job.SPD_MESSAGE */
jpText = 4, /**< Text job. SPD_TEXT */
jpProgress = 5 /**< Progress report. SPD_PROGRESS added KDE 4.4 */
};
/**
* @enum JobState
* Job states returned by method @ref getJobState.
*/
enum JobState
{
jsQueued = 0, /**< Job has been queued but is not yet speakable. */
jsFiltering = 1, /**< Job is being filtered. */
jsSpeakable = 2, /**< Job is speakable, but is not speaking. */
jsSpeaking = 3, /**< Job is currently speaking. */
jsPaused = 4, /**< Job is paused. */
jsInterrupted = 5, /**< Job is paused because it has been interrupted by another job. */
jsFinished = 6, /**< Job is finished and is deleteable. */
jsDeleted = 7 /**< Job is deleted from the queue. */
};
/**
* @enum SayOptions
* Hints about text content when sending via @ref say.
*/
enum SayOptions
{
soNone = 0x0000, /**< No options specified. Autodetected. */
soPlainText = 0x0001, /**< The text contains plain text. */
soHtml = 0x0002, /**< The text contains HTML markup. */
soSsml = 0x0004, /**< The text contains SSML markup. */
soChar = 0x0008, /**< The text should be spoken as individual characters. */
soKey = 0x0010, /**< The text contains a keyboard symbolic key name. */
soSoundIcon = 0x0020 /**< The text is the name of a sound icon. */
};
/**
* @enum TalkerCapabilities1
* Flags for synthesizer/talker capabilities.
* All items marked FALSE are hard-coded off at this time.
*/
enum TalkerCapabilities1
{
tcCanListVoices = 0x00000001,
tcCanSetVoiceByProperties = 0x00000002,
tcCanGetCurrentVoice = 0x00000004,
tcCanSetRateRelative = 0x00000008, /**< FALSE */
tcCanSetRateAbsolute = 0x00000010,
tcCanGetRateDefault = 0x00000020,
tcCanSetPitchRelative = 0x00000040, /**< FALSE */
tcCanSetPitchAbsolute = 0x00000080,
tcCanGetPitchDefault = 0x00000100,
tcCanSetPitchRangeRelative = 0x00000200, /**< FALSE */
tcCanSetPitchRangeAbsolute = 0x00000400, /**< FALSE */
tcCanGetPitchRangeDefault = 0x00000800, /**< FALSE */
tcCanSetVolumeRelative = 0x00001000, /**< FALSE */
tcCanSetVolumeAbsolute = 0x00002000,
tcCanGetVolumeDefault = 0x00004000,
tcCanSetPunctuationModeAll = 0x00008000, /**< FALSE */
tcCanSetPunctuationModeNone = 0x00010000, /**< FALSE */
tcCanSetPunctuationModeSome = 0x00020000, /**< FALSE */
tcCanSetPunctuationDetail = 0x00040000, /**< FALSE */
tcCanSetCapitalLettersModeSpelling = 0x00080000, /**< FALSE */
tcCanSetCapitalLettersModeIcon = 0x00100000, /**< FALSE */
tcCanSetCapitalLettersModePitch = 0x00200000, /**< FALSE */
tcCanSetNumberGrouping = 0x00400000, /**< FALSE */
tcCanSayTextFromPosition = 0x00800000, /**< FALSE */
tcCanSayChar = 0x01000000, /**< FALSE */
tcCanSayKey = 0x02000000, /**< FALSE */
tcCanSayIcon = 0x04000000, /**< FALSE */
tcCanSetDictionary = 0x08000000, /**< FALSE */
tcCanRetrieveAudio = 0x10000000, /**< FALSE */
tcCanPlayAudio = 0x20000000 /**< FALSE */
};
/**
* @enum TalkerCapabilities2
* All items marked FALSE are hard-coded off at this time.
*/
enum TalkerCapabilities2
{
tcCanReportEventsBySentences = 0x00000001,
tcCanReportEventsByWords = 0x00000002, /**< FALSE */
tcCanReportCustomIndexMarks = 0x00000004, /**< FALSE */
tcHonorsPerformanceGuidelines1 = 0x00000008, /**< FALSE */
tcHonorsPerformanceGuidelines2 = 0x00000010, /**< FALSE */
tcHonorsPerformanceGuidelines = 0x00000018, /**< FALSE */
tcCanDeferMessage = 0x00000020, /**< FALSE */
tcCanParseSsml = 0x00000040,
tcSupportsMultilingualUtterances = 0x00000080, /**< FALSE */
tcCanParseHtml = 0x00000100
};
/**
* @enum MarkerType
* Types of markers emitted by @ref marker signal.
*/
enum MarkerType
{
mtSentenceBegin = 0,
mtSentenceEnd = 1,
mtWordBegin = 2,
mtPhonemeBegin = 3,
mtCustom = 4
};
/**
* Constructor.
* Note: Applications do not create instances of KSpeech.
* Instead create KSpeechInterface object. See @ref programming.
*/
KSpeech(QObject *parent=0);
/**
* Destructor.
*/
~KSpeech();
public: // PROPERTIES
Q_PROPERTY(bool isSpeaking READ isSpeaking)
Q_PROPERTY(QString version READ version)
public Q_SLOTS: // METHODS
/**
* Returns true if KTTSD is currently speaking.
* @return True if currently speaking.
*/
bool isSpeaking() const;
/**
* Returns the version number of KTTSD.
* @return Version number string.
*/
QString version() const;
/**
* Returns the friendly display name for the application.
* @return Application display name.
*
* If application has not provided a friendly name, the DBUS connection name is returned.
*/
QString applicationName();
/**
* Sets a friendly display name for the application.
* @param applicationName Friendly name for the application.
*/
void setApplicationName(const QString &applicationName);
/**
* Returns the default talker for the application.
* @return Talker.
*
* The default is "", which uses the default talker configured by user.
*/
QString defaultTalker();
/**
* Sets the default talker for the application.
* @param defaultTalker Default talker. Example: "en".
*/
void setDefaultTalker(const QString &defaultTalker);
/**
* Returns the default priority for speech jobs submitted by the application.
* @return Default job priority.
*
* @see JobPriority
*/
int defaultPriority();
/**
* Sets the default priority for speech jobs submitted by the application.
* @param defaultPriority Default job priority.
*
* @see JobPriority
*/
void setDefaultPriority(int defaultPriority);
/**
* Returns the regular expression used to perform Sentence Boundary
* Detection (SBD) for the application.
* @return Sentence delimiter regular expression.
*
* The default sentence delimiter is
@verbatim
([\\.\\?\\!\\:\\;])(\\s|$|(\\n *\\n))
@endverbatim
*
* Note that backward slashes must be escaped.
*
* @see sentenceparsing
*/
QString sentenceDelimiter();
/**
* Sets the regular expression used to perform Sentence Boundary
* Detection (SBD) for the application.
* @param sentenceDelimiter Sentence delimiter regular expression.
*/
void setSentenceDelimiter(const QString &sentenceDelimiter);
/**
* Returns whether speech jobs for this application are filtered using configured
* filter plugins.
* @return True if filtering is on.
*
* Filtering is on by default.
*/
bool filteringOn();
/**
* Sets whether speech jobs for this application are filtered using configured
* filter plugins.
* @param filteringOn True to set filtering on.
*/
void setFilteringOn(bool filteringOn);
/**
* Returns whether KTTSD will automatically attempt to configure new
* talkers to meet required talker attributes.
* @return True if KTTSD will autoconfigure talkers.
*
* @see defaultTalker
*/
bool autoConfigureTalkersOn();
/** Sets whether KTTSD will automatically attempt to configure new
* talkers to meet required talker attributes.
* @param autoConfigureTalkersOn True to enable auto configuration.
*/
void setAutoConfigureTalkersOn(bool autoConfigureTalkersOn);
/**
* Returns whether application is paused.
* @return True if application is paused.
*/
bool isApplicationPaused();
/**
* Returns the full path name to XSLT file used to convert HTML
* markup to speakable form.
* @return XSLT filename.
*/
QString htmlFilterXsltFile();
/**
* Sets the full path name to an XSLT file used to convert HTML
* markup to speakable form.
* @param htmlFilterXsltFile XSLT filename.
*/
void setHtmlFilterXsltFile(const QString &htmlFilterXsltFile);
/**
* Returns the full path name to XSLT file used to convert SSML
* markup to a speakable form.
* @return XSLT filename.
*/
QString ssmlFilterXsltFile();
/**
* Sets the full path name to XSLT file used to convert SSML
* markup to a speakable form.
* @param ssmlFilterXsltFile XSLT filename.
*/
void setSsmlFilterXsltFile(const QString &ssmlFilterXsltFile);
/**
* Returns whether this is a System Manager application.
* @return True if the application is a System Manager.
*/
bool isSystemManager();
/**
* Sets whether this is a System Manager application.
* @param isSystemManager True if this is a System Manager.
*
* System Managers are used to control and configure overall TTS output.
* When True, many of the KSpeech methods alter their behavior.
*/
void setIsSystemManager(bool isSystemManager);
/**
* Creates and starts a speech job. The job is created at the application's
* default job priority using the default talker.
* @param text The text to be spoken.
* @param options Speech options.
* @return Job Number for the new job.
*
* @see JobPriority
* @see SayOptions
*/
int say(const QString &text, int options);
/**
* Creates and starts a speech job from a specified file.
* @param filename Full path name of the file.
* @param encoding The encoding of the file. Default UTF-8.
* @return Job Number for the new job.
*
* The job is spoken using application's default talker.
* @see defaultTalker
*
* Plain text is parsed into individual sentences using the current sentence delimiter.
* Call @ref setSentenceDelimiter to change the sentence delimiter prior to calling sayFile.
* Call @ref getSentenceCount to retrieve the sentence count after calling sayFile.
*
* The text may contain speech mark language, such as SMML,
* provided that the speech plugin/engine support it. In this case,
* sentence parsing follows the semantics of the markup language.
*/
int sayFile(const QString &filename, const QString &encoding);
/**
* Submits a speech job from the contents of the clipboard.
* The job is spoken using application's default talker.
* @return Job Number for the new job.
*
* @see defaultTalker
*/
int sayClipboard();
/**
* Pauses speech jobs belonging to the application.
* When called by a System Manager, pauses all jobs of all applications.
*/
void pause();
/**
* Resumes speech jobs belonging to the application.
* When called by a System Manager, resumes all jobs of all applications.
*/
void resume();
void stop();
void cancel();
void setSpeed(int speed);
void setPitch(int pitch);
void setVolume(int volume);
/**
* Removes the specified job. If the job is speaking, it is stopped.
* @param jobNum Job Number. If 0, the last job submitted by
* the application.
*/
void removeJob(int jobNum);
/**
* Removes all jobs belonging to the application.
* When called from a System Manager, removes all jobs of all applications.
*/
void removeAllJobs();
/**
* Returns the number of sentences in a job.
* @param jobNum Job Number. If 0, the last job submitted by
* the application.
* @return Number of sentences in the job.
*/
int getSentenceCount(int jobNum);
/**
* Returns the job number of the currently speaking job (any application).
* @return Job Number
*/
int getCurrentJob();
/**
* Returns the number of jobs belonging to the application
* with the specified job priority.
* @param priority Job Priority.
* @return Number of jobs.
*
* If priority is KSpeech::jpAll, returns the number of jobs belonging
* to the application (all priorities).
*
* When called from a System Manager, returns count of all jobs of the
* specified priority for all applications.
*
* @see JobPriority
*/
int getJobCount(int priority);
/**
* Returns a list job numbers for the jobs belonging to the
* application with the specified priority.
* @param priority Job Priority.
* @return List of job numbers. Note that the numbers
* are strings.
*
* If priority is KSpeech::jpAll, returns the job numbers belonging
* to the application (all priorities).
*
* When called from a System Manager, returns job numbers of the
* specified priority for all applications.
*
* @see JobPriority
*/
QStringList getJobNumbers(int priority);
/**
* Returns the state of a job.
* @param jobNum Job Number. If 0, the last job submitted by
* the application.
* @return Job state.
*
* @see JobState
*/
int getJobState(int jobNum);
/**
* Get information about a job.
* @param jobNum Job Number. If 0, the last job submitted by
* the application.
* @return A QDataStream containing information about the job.
* Blank if no such job.
*
* The stream contains the following elements:
* - int priority Job Type.
* - int state Job state.
* - QString appId DBUS senderId of the application that requested the speech job.
* - QString talker Talker code as requested by application.
* - int sentenceNum Current sentence being spoken. Sentences are numbered starting at 1.
* - int sentenceCount Total number of sentences in the job.
* - QString applicationName Application's friendly name (if provided by app)
*
* If the job is currently filtering, waits for that to finish before returning.
*
* The following sample code will decode the stream:
@verbatim
QByteArray jobInfo = m_kspeech->getJobInfo(jobNum);
if (jobInfo != QByteArray()) {
QDataStream stream(&jobInfo, QIODevice::ReadOnly);
qint32 priority;
qint32 state;
QString talker;
qint32 sentenceNum;
qint32 sentenceCount;
QString applicationName;
stream >> priority;
stream >> state;
stream >> appId;
stream >> talker;
stream >> sentenceNum;
stream >> sentenceCount;
stream >> applicationName;
};
@endverbatim
*/
QByteArray getJobInfo(int jobNum);
/**
* Return a sentence of a job.
* @param jobNum Job Number. If 0, the last job submitted by
* the application.
* @param sentenceNum Sentence Number. Sentence numbers start at 1.
* @return The specified sentence in the specified job. If no such
* job or sentence, returns "".
*/
QString getJobSentence(int jobNum, int sentenceNum);
/**
* Return a list of full Talker Codes for configured talkers.
* @return List of Talker codes.
*/
QStringList getTalkerCodes();
/**
* Given a talker, returns the Talker ID for the talker.
* that will speak the job.
* @param talker Talker. Example: "en".
* @return Talker ID. A Talker ID is an internally-assigned
* identifier for a talker.
*
* This method is normally used only by System Managers.
*/
QString talkerToTalkerId(const QString &talker);
/**
* Returns a bitarray giving the capabilities of a talker.
* @param talker Talker. Example: "en".
* @return A word with bits set according to the capabilities
* of the talker.
*
* @see TalkerCapabilities1
* @see getTalkerCapabilities2
*/
int getTalkerCapabilities1(const QString &talker);
/**
* Returns a bitarray giving the capabilities of a talker.
* @param talker Talker. Example: "en".
* @return A word with bits set according to the capabilities
* of the talker.
*
* @see TalkerCapabilities2
* @see getTalkerCapabilities1
*/
int getTalkerCapabilities2(const QString &talker);
/**
* Return a list of the voice codes of voices available in the synthesizer
* corresponding to a talker.
* @param talker Talker. Example: "synthesizer='Festival'"
* @return List of voice codes.
*
* Voice codes are synthesizer specific.
*/
QStringList getTalkerVoices(const QString &talker);
/**
* Change the talker of an already-submitted job.
* @param jobNum Job Number. If 0, the last job submitted by
* the application.
* @param talker Desired new talker.
*/
void changeJobTalker(int jobNum, const QString &talker);
/**
* Move a job one position down in the queue so that it is spoken later.
* If the job is already speaking, it is stopped and will resume
* when processing next gets to it.
* @param jobNum Job Number. If 0, the last job submitted by
* the application.
*
* Since there is only one ScreenReaderOutput, this method is meaningless
* for ScreenReaderOutput jobs.
*/
void moveJobLater(int jobNum);
/**
* Advance or rewind N sentences in a job.
* @param jobNum Job Number. If 0, the last job submitted by
* the application.
* @param n Number of sentences to advance (positive) or rewind (negative)
* in the job.
* @return Number of the sentence actually moved to. Sentence numbers
* are numbered starting at 1.
*
* If no such job, does nothing and returns 0.
* If n is zero, returns the current sentence number of the job.
* Does not affect the current speaking/not-speaking state of the job.
*
* Since ScreenReaderOutput jobs are not split into sentences, this method
* is meaningless for ScreenReaderOutput jobs.
*/
int moveRelSentence(int jobNum, int n);
/**
* Display the KttsMgr program so that user can configure KTTS options.
* Only one instance of KttsMgr is displayed.
*/
void showManagerDialog();
/**
* Shuts down KTTSD. Do not call this!
*/
void kttsdExit();
/**
* post ctor helper method that instantiates the dbus adaptor class, and registers
*/
void init();
/**
* Cause KTTSD to re-read its configuration.
*/
void reinit();
/** Called by DBusAdaptor so that KTTSD knows the application that
* called it.
* @param appId DBUS connection name that called KSpeech.
*/
void setCallingAppId(const QString& appId);
Q_SIGNALS: // SIGNALS
/**
* This signal is emitted when KTTSD starts.
*/
void kttsdStarted();
/**
* This signal is emitted just before KTTS exits.
*/
void kttsdExiting();
/**
* This signal is emitted each time the state of a job changes.
* @param appId The DBUS connection name of the application that
* submitted the job.
* @param jobNum Job Number.
* @param state Job state. @ref JobState.
*/
void jobStateChanged(const QString &appId, int jobNum, int state);
/**
* This signal is emitted when a marker is processed.
* Currently only emits mtSentenceBegin and mtSentenceEnd.
* @param appId The DBUS connection name of the application that submitted the job.
* @param jobNum Job Number of the job emitting the marker.
* @param markerType The type of marker.
* Currently either mtSentenceBegin or mtSentenceEnd.
* @param markerData Data for the marker.
* Currently, this is the sentence number of the sentence
* begun or ended. Sentence numbers begin at 1.
*/
void marker(const QString &appId, int jobNum, int markerType, const QString &markerData);
/**
* This signal is emitted when a new job coming in is filtered (or not filtered if no filters
* are on).
* @param prefilterText The text of the speech job
* @param postfilterText The text of the speech job after any filters have been applied
*/
void newJobFiltered(const QString &prefilterText, const QString &postfilterText);
private Q_SLOTS:
void slotJobStateChanged(const QString& appId, int jobNum, KSpeech::JobState state);
void slotMarker(const QString& appId, int jobNum, KSpeech::MarkerType markerType, const QString& markerData);
void slotFilteringFinished();
private:
/**
* The DBUS connection name of the last application that called KTTSD.
*/
QString callingAppId();
/*
* Checks if KTTSD is ready to speak and at least one talker is configured.
* If not, user is prompted to display the configuration dialog.
*/
bool ready();
/**
* Create and initialize the Configuration Data object.
*/
bool initializeConfigData();
/*
* Create and initialize the TalkerMgr object.
*/
bool initializeTalkerMgr();
/*
* Create and initialize the speaker.
*/
bool initializeSpeaker();
/*
* If a job number is 0, returns the default job number for a command.
* Returns the job number of the last job queued by the application, or if
* no such job, the current job number.
* @param jobNum The job number passed in the DBUS message. May be 0.
* @return Default job number. 0 if no such job.
*/
int applyDefaultJobNum(int jobNum);
/*
* Announces an event to kDebug.
*/
void announceEvent(const QString& slotName, const QString& eventName);
void announceEvent(const QString& slotName, const QString& eventName, const QString& appId,
int jobNum, MarkerType markerType, const QString& markerData);
void announceEvent(const QString& slotName, const QString& eventName, const QString& appId,
int jobNum, JobState state);
private:
KSpeechPrivate* d;
};
#endif // KSPEECH_H

View file

@ -1 +0,0 @@
enum { LibraryNeedsAtLeastOneSourceFile = 0 };

View file

@ -1,284 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/kde/KSpeech">
<interface name="org.kde.KSpeech">
<property name="version" type="s" access="read"/>
<property name="isSpeaking" type="b" access="read"/>
<method name="applicationName">
<arg type="s" direction="out"/>
</method>
<method name="setApplicationName">
<arg name="applicationName" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="defaultTalker">
<arg type="s" direction="out"/>
</method>
<method name="setDefaultTalker">
<arg name="defaultTalker" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="defaultPriority">
<arg type="i" direction="out"/>
</method>
<method name="setDefaultPriority">
<arg name="defaultPriority" type="i" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="sentenceDelimiter">
<arg type="s" direction="out"/>
</method>
<method name="setSentenceDelimiter">
<arg name="sentenceDelimiter" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="filteringOn">
<arg type="b" direction="out"/>
</method>
<method name="setFilteringOn">
<arg name="filteringOn" type="b" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="autoConfigureTalkersOn">
<arg type="b" direction="out"/>
</method>
<method name="setAutoConfigureTalkersOn">
<arg name="autoConfigureTalkersOn" type="b" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="isApplicationPaused">
<arg type="b" direction="out"/>
</method>
<method name="htmlFilterXsltFile">
<arg type="s" direction="out"/>
</method>
<method name="setHtmlFilterXsltFile">
<arg name="htmlFilterXsltFile" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="ssmlFilterXsltFile">
<arg type="s" direction="out"/>
</method>
<method name="setSsmlFilterXsltFile">
<arg name="ssmlFilterXsltFile" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="isSystemManager">
<arg type="b" direction="out"/>
</method>
<method name="setIsSystemManager">
<arg name="isSystemManager" type="b" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="say">
<arg name="text" type="s" direction="in"/>
<arg name="options" type="i" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="sayFile">
<arg name="filename" type="s" direction="in"/>
<arg name="encoding" type="s" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="sayClipboard">
<arg type="i" direction="out"/>
</method>
<method name="outputModules">
<arg type="as" direction="out"/>
</method>
<method name="languagesByModule">
<arg name="module" type="s" direction="in"/>
<arg type="as" direction="out"/>
</method>
<method name="getPossibleTalkers">
<arg type="as" direction="out"/>
</method>
<method name="stop">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="cancel">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="pause">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="resume">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="setOutputModule">
<arg name="module" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="setLanguage">
<arg name="language" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="setVoiceType">
<arg name="voiceType" type="i" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="setPunctuationType">
<arg name="punctuation" type="i" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="setSpeed">
<arg name="speed" type="i" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="setPitch">
<arg name="pitch" type="i" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="setVolume">
<arg name="volume" type="i" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="removeJob">
<arg name="jobNum" type="i" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="removeAllJobs">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="getSentenceCount">
<arg name="jobNum" type="i" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="getCurrentJob">
<arg type="i" direction="out"/>
</method>
<method name="getJobCount">
<arg name="priority" type="i" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="getJobNumbers">
<arg name="priority" type="i" direction="in"/>
<arg type="as" direction="out"/>
</method>
<method name="getJobState">
<arg name="jobNum" type="i" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="getJobInfo">
<arg name="jobNum" type="i" direction="in"/>
<arg type="ay" direction="out"/>
</method>
<method name="getJobSentence">
<arg name="jobNum" type="i" direction="in"/>
<arg name="sentenceNum" type="i" direction="in"/>
<arg type="s" direction="out"/>
</method>
<method name="getTalkerCodes">
<arg type="as" direction="out"/>
</method>
<method name="talkerToTalkerId">
<arg name="talker" type="s" direction="in"/>
<arg type="s" direction="out"/>
</method>
<method name="getTalkerCapabilities1">
<arg name="talker" type="s" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="getTalkerCapabilities2">
<arg name="talker" type="s" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="getTalkerVoices">
<arg name="talker" type="s" direction="in"/>
<arg type="as" direction="out"/>
</method>
<method name="changeJobTalker">
<arg name="jobNum" type="i" direction="in"/>
<arg name="talker" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="moveJobLater">
<arg name="jobNum" type="i" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="moveRelSentence">
<arg name="jobNum" type="i" direction="in"/>
<arg name="n" type="i" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="showManagerDialog">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="kttsdExit">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="reinit">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<signal name="kttsdStarted"/>
<signal name="kttsdExiting"/>
<signal name="jobStateChanged">
<arg name="appId" type="s"/>
<arg name="jobNum" type="i"/>
<arg name="state" type="i"/>
</signal>
<signal name="marker">
<arg name="appId" type="s"/>
<arg name="jobNum" type="i"/>
<arg name="markerType" type="i"/>
<arg name="markerData" type="s"/>
</signal>
</interface>
</node>

View file

@ -87,14 +87,6 @@
2000 kfind
2001 kregexpeditor
# kdeaccessibility
2400 kttsd (daemon)
2401 kttsmgr (systray app)
2402 kttsjobmgr (job mgr kcm)
2403 kspeak (scripted app)
2404 kcmkttsmgr (kcm)
2405 libkttsd (library)
# 2500-2999 Reserved for private use
# kdegraphics
@ -199,6 +191,9 @@
# khttp
51007 khttp
# kspeech
51008 kspeech
# kdemultimedia
67100 kmix

View file

@ -5,6 +5,8 @@ include_directories(
${CMAKE_SOURCE_DIR}/interfaces/kregexpeditor
${CMAKE_SOURCE_DIR}/kdecore/sonnet
${CMAKE_SOURCE_DIR}/kdeui
${CMAKE_SOURCE_DIR}/kutils/kspeech
${CMAKE_BINARY_DIR}/kutils/kspeech
${KDE4_KDECORE_INCLUDES}
actions
colors
@ -347,6 +349,7 @@ target_link_libraries(kdeui PRIVATE
target_link_libraries(kdeui PUBLIC
${KDE4_KDECORE_LIBS}
${KDE4_KSPEECH_LIBS}
${QT_QTGUI_LIBRARY}
${QT_QTXML_LIBRARY}
${QT_QTNETWORK_LIBRARY}

View file

@ -20,8 +20,6 @@
*/
#include "ktextedit.h"
#include <ktoolinvocation.h>
#include <kdebug.h>
#include <QApplication>
#include <QClipboard>
@ -31,13 +29,12 @@
#include <QScrollBar>
#include <QTextCursor>
#include <QTextDocumentFragment>
#include <QDBusInterface>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <configdialog.h>
#include <dialog.h>
#include "backgroundchecker.h"
#include <kdebug.h>
#include <kspeech.h>
#include <kaction.h>
#include <kcursor.h>
#include <kglobalsettings.h>
@ -578,33 +575,25 @@ QMenu *KTextEdit::mousePopupMenu()
popup->addAction(replaceAction);
}
}
popup->addSeparator();
QAction *speakAction = popup->addAction(i18n("Speak Text"));
speakAction->setIcon(KIcon("preferences-desktop-text-to-speech"));
speakAction->setEnabled(!emptyDocument );
connect( speakAction, SIGNAL(triggered(bool)), this, SLOT(slotSpeakText()) );
if (KSpeech::isSupported()) {
popup->addSeparator();
QAction *speakAction = popup->addAction(i18n("Speak Text"));
speakAction->setIcon(KIcon("preferences-desktop-text-to-speech"));
speakAction->setEnabled(!emptyDocument );
connect( speakAction, SIGNAL(triggered(bool)), this, SLOT(slotSpeakText()) );
}
return popup;
}
void KTextEdit::slotSpeakText()
{
// If KTTSD not running, start it.
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd"))
{
QString error;
if (KToolInvocation::startServiceByDesktopName("kttsd", QStringList(), &error))
{
KMessageBox::error(this, i18n( "Starting Jovie Text-to-Speech Service Failed"), error );
return;
}
}
QDBusInterface ktts("org.kde.kttsd", "/KSpeech", "org.kde.KSpeech");
QString text;
if(textCursor().hasSelection())
text = textCursor().selectedText();
else
text = toPlainText();
ktts.asyncCall("say", text, 0);
KSpeech kspeech(this);
kspeech.say(text);
}
void KTextEdit::contextMenuEvent(QContextMenuEvent *event)

View file

@ -4,6 +4,8 @@ include_directories(
${KDE4_KIO_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/kutils/kspeech
${CMAKE_BINARY_DIR}/kutils/kspeech
)
if(ENABLE_TESTING)

View file

@ -22,6 +22,7 @@
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <kspeech.h>
KNotifyConfigActionsWidget::KNotifyConfigActionsWidget( QWidget * parent )
: QWidget(parent)

View file

@ -116,7 +116,7 @@
</sizepolicy>
</property>
<property name="whatsThis" >
<string>&lt;qt>Specifies how Jovie should speak the event when received. If you select "Speak custom text", enter the text in the box. You may use the following substitution strings in the text:&lt;dl>&lt;dt>%e&lt;/dt>&lt;dd>Name of the event&lt;/dd>&lt;dt>%a&lt;/dt>&lt;dd>Application that sent the event&lt;/dd>&lt;dt>%m&lt;/dt>&lt;dd>The message sent by the application&lt;/dd>&lt;/dl>&lt;/qt></string>
<string>&lt;qt>Specifies how Text-To-Speech should speak the event when received. If you select "Speak custom text", enter the text in the box. You may use the following substitution strings in the text:&lt;dl>&lt;dt>%e&lt;/dt>&lt;dd>Name of the event&lt;/dd>&lt;dt>%a&lt;/dt>&lt;dd>Application that sent the event&lt;/dd>&lt;dt>%m&lt;/dt>&lt;dd>The message sent by the application&lt;/dd>&lt;/dl>&lt;/qt></string>
</property>
<item>
<property name="text" >
@ -138,7 +138,7 @@
<item row="5" column="3" >
<widget class="KLineEdit" name="KTTS_select" >
<property name="whatsThis" >
<string>&lt;qt>Specifies how Jovie should speak the event when received. If you select "Speak custom text", enter the text in the box. You may use the following substitution strings in the text:&lt;dl>&lt;dt>%e&lt;/dt>&lt;dd>Name of the event&lt;/dd>&lt;dt>%a&lt;/dt>&lt;dd>Application that sent the event&lt;/dd>&lt;dt>%m&lt;/dt>&lt;dd>The message sent by the application&lt;/dd>&lt;/dl>&lt;/qt></string>
<string>&lt;qt>Specifies how Text-To-Speech should speak the event when received. If you select "Speak custom text", enter the text in the box. You may use the following substitution strings in the text:&lt;dl>&lt;dt>%e&lt;/dt>&lt;dd>Name of the event&lt;/dd>&lt;dt>%a&lt;/dt>&lt;dd>Application that sent the event&lt;/dd>&lt;dt>%m&lt;/dt>&lt;dd>The message sent by the application&lt;/dd>&lt;/dl>&lt;/qt></string>
</property>
</widget>
</item>

View file

@ -25,6 +25,7 @@
#include <kdebug.h>
#include <kstandarddirs.h>
#include <kservice.h>
#include <kspeech.h>
KNotifyConfigElement::KNotifyConfigElement(const QString &eventid, KConfig *config)
: m_config( new KConfigGroup(config , "Event/" + eventid) )
@ -63,6 +64,5 @@ void KNotifyConfigElement::save( )
bool KNotifyConfigElement::have_kttsd() //[static]
{
static bool val = KService::serviceByDesktopName("kttsd");
return val;
return KSpeech::isSupported();
}

View file

@ -13,6 +13,7 @@ add_subdirectory(kpasswdstore)
add_subdirectory(kpowermanager)
add_subdirectory(kdnssd)
add_subdirectory(khttp)
add_subdirectory(kspeech)
######## kidletime ####################

View file

@ -0,0 +1,41 @@
if(SPEECHD_FOUND)
include_directories(${SPEECHD_INCLUDE_DIR})
add_definitions(-DHAVE_SPEECHD)
endif()
add_definitions(-DKDE_DEFAULT_DEBUG_AREA=51008)
set(kspeech_LIB_SRCS
kspeech.cpp
)
add_library(kspeech ${LIBRARY_TYPE} ${kspeech_LIB_SRCS})
target_link_libraries(kspeech PUBLIC
${KDE4_KDECORE_LIBS}
)
if(SPEECHD_FOUND)
target_link_libraries(kspeech PRIVATE ${SPEECHD_LIBRARIES})
endif()
set_target_properties(kspeech PROPERTIES
VERSION ${GENERIC_LIB_VERSION}
SOVERSION ${GENERIC_LIB_SOVERSION}
)
generate_export_header(kspeech)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/kspeech_export.h
kspeech.h
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}
COMPONENT Devel
)
install(
TARGETS kspeech
EXPORT kdelibsLibraryTargets
${INSTALL_TARGETS_DEFAULT_ARGS}
)

200
kutils/kspeech/kspeech.cpp Normal file
View file

@ -0,0 +1,200 @@
/* This file is part of the KDE libraries
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kspeech.h"
#include <QCoreApplication>
#include <kdebug.h>
#if defined(HAVE_SPEECHD)
# include <speech-dispatcher/libspeechd.h>
#endif
static KSpeechPrivate* s_kspeechprivate = nullptr;
// NOTE: the callback function is not called in the same thread as the object that opens the
// connection
class KSpeechPrivate : public QObject
{
friend class KSpeech;
Q_OBJECT
public:
KSpeechPrivate(QObject *parent);
~KSpeechPrivate();
#if defined(HAVE_SPEECHD)
static void speechCallback(size_t msg_id, size_t client_id, SPDNotificationType state);
#endif
Q_SIGNALS:
void signalJobStateChanged(int jobNum, int state);
private:
#if defined(HAVE_SPEECHD)
SPDConnection* m_speechd;
#endif
QByteArray m_speechid;
};
KSpeechPrivate::KSpeechPrivate(QObject *parent)
: QObject(parent)
#if defined(HAVE_SPEECHD)
, m_speechd(nullptr)
#endif
{
if (Q_UNLIKELY(s_kspeechprivate)) {
kWarning() << "Multiple KSpeech instances are not supported";
}
s_kspeechprivate = this;
m_speechid = QCoreApplication::applicationName().toLocal8Bit();
}
KSpeechPrivate::~KSpeechPrivate()
{
s_kspeechprivate = nullptr;
}
#if defined(HAVE_SPEECHD)
void KSpeechPrivate::speechCallback(size_t msg_id, size_t client_id, SPDNotificationType state)
{
Q_UNUSED(client_id);
// qDebug() << Q_FUNC_INFO << msg_id << client_id << state;
if (Q_UNLIKELY(!s_kspeechprivate)) {
kWarning() << "Null kspeech private pointer";
return;
}
const int jobNum = msg_id;
switch (state) {
case SPD_EVENT_BEGIN: {
emit s_kspeechprivate->signalJobStateChanged(jobNum, KSpeech::JobStarted);
break;
}
case SPD_EVENT_END: {
emit s_kspeechprivate->signalJobStateChanged(jobNum, KSpeech::JobFinished);
break;
}
case SPD_EVENT_CANCEL: {
emit s_kspeechprivate->signalJobStateChanged(jobNum, KSpeech::JobCanceled);
break;
}
default: {
break;
}
}
}
#endif // HAVE_SPEECHD
KSpeech::KSpeech(QObject* parent)
: QObject(parent),
d(new KSpeechPrivate(this))
{
connect(
d, SIGNAL(signalJobStateChanged(int,int)),
this, SLOT(_jobStateChanged(int,int))
);
}
KSpeech::~KSpeech()
{
removeAllJobs();
delete d;
}
bool KSpeech::isSupported()
{
#if defined(HAVE_SPEECHD)
return true;
#else
return false;
#endif
}
void KSpeech::setSpeechID(const QString &id)
{
removeAllJobs();
d->m_speechid = id.toUtf8();
}
int KSpeech::say(const QString &text)
{
#if defined(HAVE_SPEECHD)
if (!d->m_speechd) {
d->m_speechd = spd_open(d->m_speechid.constData(), "main", NULL, SPD_MODE_THREADED);
if (Q_UNLIKELY(!d->m_speechd)) {
kWarning() << "Could not open speech-dispatcher connection";
return 0;
}
d->m_speechd->callback_begin = KSpeechPrivate::speechCallback;
d->m_speechd->callback_end = KSpeechPrivate::speechCallback;
d->m_speechd->callback_cancel = KSpeechPrivate::speechCallback;
spd_set_notification_on(d->m_speechd, SPD_BEGIN);
spd_set_notification_on(d->m_speechd, SPD_END);
spd_set_notification_on(d->m_speechd, SPD_CANCEL);
}
const QByteArray textbytes = text.toUtf8();
const int jobNum = spd_say(d->m_speechd, SPD_TEXT, textbytes.constData());
if (jobNum < 0) {
kWarning() << "Speech-dispatcher say failed";
return 0;
}
// qDebug() << Q_FUNC_INFO << jobNum << spd_get_client_id(d->m_speechd);
return jobNum;
#else
kWarning() << "KSpeech is a stub";
return 0;
#endif // HAVE_SPEECHD
}
void KSpeech::removeAllJobs()
{
#if defined(HAVE_SPEECHD)
if (Q_UNLIKELY(!d->m_speechd)) {
kDebug() << "Null speech-dispatcher pointer";
return;
}
spd_stop(d->m_speechd);
spd_close(d->m_speechd);
d->m_speechd = nullptr;
#endif
}
void KSpeech::removeJob(int jobNum)
{
#if defined(HAVE_SPEECHD)
if (Q_UNLIKELY(!d->m_speechd)) {
kWarning() << "Null speech-dispatcher pointer";
return;
}
spd_stop_uid(d->m_speechd, jobNum);
#endif
}
void KSpeech::_jobStateChanged(int jobNum, int state)
{
emit jobStateChanged(jobNum, state);
}
#include "kspeech.moc"

69
kutils/kspeech/kspeech.h Normal file
View file

@ -0,0 +1,69 @@
/* This file is part of the KDE libraries
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KSPEECH_H
#define KSPEECH_H
#include "kspeech_export.h"
#include <QObject>
class KSpeechPrivate;
/*!
Class for Text To Speech.
@since 4.22
@warning the API is subject to change
@todo implement configuration options
*/
class KSPEECH_EXPORT KSpeech : public QObject
{
Q_OBJECT
public:
enum KSpeechState {
JobStarted = 0,
JobFinished = 1,
JobCanceled = 2
};
KSpeech(QObject* parent = nullptr);
~KSpeech();
static bool isSupported();
void setSpeechID(const QString &id);
public Q_SLOTS:
int say(const QString &text);
void removeAllJobs();
void removeJob(int jobNum);
Q_SIGNALS:
void jobStateChanged(int jobNum, int state);
private Q_SLOTS:
void _jobStateChanged(int jobNum, int state);
private:
Q_DISABLE_COPY(KSpeech);
KSpeechPrivate* const d;
};
#endif // KSPEECH_H