1 /***************************************************************************
2 texttospeechsystem.cpp - description
5 copyright : (C) 2002 by Gunnar Schmi Dt
6 email : kmouth@schmi-dt.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "texttospeechsystem.h"
21 #include <QtCore/QTextCodec>
22 #include <QtDBus/QtDBus>
25 #include <kconfiggroup.h>
28 #include <kspeech_interface.h>
32 TextToSpeechSystem::TextToSpeechSystem() {
36 codec
= Speech::Local
; // local encoding;
40 TextToSpeechSystem::~TextToSpeechSystem() {
44 bool kttsdSay (const QString
&text
, const QString
&language
) {
45 // TODO: Would be better to save off this QDBusInterface pointer and
46 // set defaults only once.
47 org::kde::KSpeech
kspeech("org.kde.kttsd", "/KSpeech", QDBusConnection::sessionBus());
48 kspeech
.setApplicationName("KMouth");
49 kspeech
.setDefaultTalker(language
);
51 // FIXME: language is incorrect.
52 kDebug() << "kttsdSay: language = " << language
;
53 kspeech
.setDefaultPriority(KSpeech::jpWarning
);
54 QDBusReply
<int> val
= kspeech
.say(text
, 0);
59 void TextToSpeechSystem::speak (const QString
&text
, const QString
&language
) {
60 if (text
.length() > 0) {
62 if (kttsdSay(text
, language
))
66 if (codec
< Speech::UseCodec
)
67 (new Speech())->speak(ttsCommand
, stdIn
, text
, language
, codec
, 0);
69 (new Speech())->speak(ttsCommand
, stdIn
, text
, language
, Speech::UseCodec
,
70 codecList
->at (codec
- Speech::UseCodec
));
74 void TextToSpeechSystem::readOptions (KConfig
*config
, const QString
&langGroup
) {
75 KConfigGroup
cg(config
, langGroup
);
76 ttsCommand
= cg
.readPathEntry("Command", QString());
77 stdIn
= cg
.readEntry("StdIn", true);
78 useKttsd
= cg
.readEntry("useKttsd", true);
80 QString codecString
= cg
.readEntry("Codec", "Local");
81 if (codecString
== "Local")
82 codec
= Speech::Local
;
83 else if (codecString
== "Latin1")
84 codec
= Speech::Latin1
;
85 else if (codecString
== "Unicode")
86 codec
= Speech::Unicode
;
88 codec
= Speech::Local
;
89 for (int i
= 0; i
< codecList
->count(); i
++ )
90 if (codecString
== codecList
->at(i
)->name())
91 codec
= Speech::UseCodec
+ i
;
95 void TextToSpeechSystem::saveOptions (KConfig
*config
, const QString
&langGroup
) {
96 KConfigGroup
cg(config
, langGroup
);
97 cg
.writePathEntry("Command", ttsCommand
);
98 cg
.writeEntry("StdIn", stdIn
);
99 cg
.writeEntry("useKttsd", useKttsd
);
100 if (codec
== Speech::Local
)
101 cg
.writeEntry("Codec", "Local");
102 else if (codec
== Speech::Latin1
)
103 cg
.writeEntry("Codec", "Latin1");
104 else if (codec
== Speech::Unicode
)
105 cg
.writeEntry("Codec", "Unicode");
107 QString codeName
= codecList
->at (codec
-Speech::UseCodec
)->name();
108 cg
.writeEntry("Codec", codeName
);
112 void TextToSpeechSystem::buildCodecList () {
113 codecList
= new QList
<QTextCodec
*>;
114 QList
<QByteArray
> availableCodecs
= QTextCodec::availableCodecs();
115 for (int i
= 0; i
< availableCodecs
.count(); ++i
) {
116 QTextCodec
*codec
= QTextCodec::codecForName(availableCodecs
[i
]);
117 codecList
->append (codec
);
121 #include "texttospeechsystem.moc"