SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kmouth / texttospeechsystem.cpp
blobbc1ff271f64a6bcc90731fbc68b9c1b51eb961b2
1 /***************************************************************************
2 texttospeechsystem.cpp - description
3 -------------------
4 begin : Son Sep 8 2002
5 copyright : (C) 2002 by Gunnar Schmi Dt
6 email : kmouth@schmi-dt.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
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. *
15 * *
16 ***************************************************************************/
18 #include "texttospeechsystem.h"
19 #include <stdlib.h>
21 #include <QtCore/QTextCodec>
22 #include <QtDBus/QtDBus>
24 #include <kconfig.h>
25 #include <kconfiggroup.h>
26 #include <kspeech.h>
27 #include <kdebug.h>
28 #include <kspeech_interface.h>
30 #include "speech.h"
32 TextToSpeechSystem::TextToSpeechSystem() {
33 ttsCommand = "";
34 stdIn = true;
35 useKttsd = true;
36 codec = Speech::Local; // local encoding;
37 buildCodecList();
40 TextToSpeechSystem::~TextToSpeechSystem() {
41 delete codecList;
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);
56 return (val>0);
59 void TextToSpeechSystem::speak (const QString &text, const QString &language) {
60 if (text.length() > 0) {
61 if (useKttsd) {
62 if (kttsdSay(text, language))
63 return;
66 if (codec < Speech::UseCodec)
67 (new Speech())->speak(ttsCommand, stdIn, text, language, codec, 0);
68 else
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;
87 else {
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");
106 else {
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"