From 00bb99ac80741fc50ef8a289719373032f2391eb Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaccessibility@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kmouth/texttospeechsystem.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 kmouth/texttospeechsystem.cpp (limited to 'kmouth/texttospeechsystem.cpp') diff --git a/kmouth/texttospeechsystem.cpp b/kmouth/texttospeechsystem.cpp new file mode 100644 index 0000000..4aeb0f9 --- /dev/null +++ b/kmouth/texttospeechsystem.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + texttospeechsystem.cpp - description + ------------------- + begin : Son Sep 8 2002 + copyright : (C) 2002 by Gunnar Schmi Dt + email : kmouth@schmi-dt.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#include "texttospeechsystem.h" +#include +#include +#include +#include + +#include +#include +#include + +#include "speech.h" + +TextToSpeechSystem::TextToSpeechSystem() { + ttsCommand = ""; + stdIn = true; + useKttsd = true; + codec = Speech::Local; // local encoding; + buildCodecList(); +} + +TextToSpeechSystem::~TextToSpeechSystem() { + delete codecList; +} + +bool kttsdSay (const QString &text, const QString &language) { + DCOPClient *client = kapp->dcopClient(); + QByteArray data; + QCString replyType; + QByteArray replyData; + QDataStream arg(data, IO_WriteOnly); + arg << text << language; + return client->call("kttsd", "KSpeech", "sayWarning(QString,QString)", + data, replyType, replyData, true); +} + +void TextToSpeechSystem::speak (const QString &text, const QString &language) { + if (text.length() > 0) { + if (useKttsd) { + if (kttsdSay(text, language)) + return; + } + + if (codec < Speech::UseCodec) + (new Speech())->speak(ttsCommand, stdIn, text, language, codec, 0); + else + (new Speech())->speak(ttsCommand, stdIn, text, language, Speech::UseCodec, + codecList->at (codec - Speech::UseCodec)); + } +} + +void TextToSpeechSystem::readOptions (KConfig *config, const QString &langGroup) { + config->setGroup(langGroup); + ttsCommand = config->readPathEntry("Command"); + stdIn = config->readBoolEntry("StdIn", true); + useKttsd = config->readBoolEntry("useKttsd", true); + + QString codecString = config->readEntry("Codec", "Local"); + if (codecString == "Local") + codec = Speech::Local; + else if (codecString == "Latin1") + codec = Speech::Latin1; + else if (codecString == "Unicode") + codec = Speech::Unicode; + else { + codec = Speech::Local; + for (uint i = 0; i < codecList->count(); i++ ) + if (codecString == codecList->at(i)->name()) + codec = Speech::UseCodec + i; + } +} + +void TextToSpeechSystem::saveOptions (KConfig *config, const QString &langGroup) { + config->setGroup(langGroup); + config->writePathEntry("Command", ttsCommand); + config->writeEntry("StdIn", stdIn); + config->writeEntry("useKttsd", useKttsd); + if (codec == Speech::Local) + config->writeEntry("Codec", "Local"); + else if (codec == Speech::Latin1) + config->writeEntry("Codec", "Latin1"); + else if (codec == Speech::Unicode) + config->writeEntry("Codec", "Unicode"); + else config->writeEntry("Codec", + codecList->at (codec-Speech::UseCodec)->name()); + +} + +void TextToSpeechSystem::buildCodecList () { + codecList = new QPtrList; + QTextCodec *codec; + int i; + for (i = 0; (codec = QTextCodec::codecForIndex(i)); i++) + codecList->append (codec); +} + +#include "texttospeechsystem.moc" -- cgit v1.2.3