1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 This file is the template for the processing plug ins.
4 Copyright : (C) 2002-2003 by José Pablo Ezequiel "Pupeno" Fernández <pupeno@kde.org>
6 Original author: José Pablo Ezequiel "Pupeno" Fernández <pupeno@kde.org>
7 Current Maintainer: Gary Cramblitt <garycramblitt@comcast.net>
8 ******************************************************************************/
10 /***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; version 2 of the License or *
15 * (at your option) version 3. *
17 ***************************************************************************/
19 // PlugInProc includes.
20 #include "pluginproc.h"
21 #include "pluginproc.moc"
24 #include <QtCore/QTextCodec>
28 #include <kstandarddirs.h>
34 PlugInProc::PlugInProc( QObject
*parent
, const char *name
) : QObject(parent
){
36 // kDebug() << "PlugInProc::PlugInProc: Running";
42 PlugInProc::~PlugInProc(){
43 // kDebug() << "PlugInProc::~PlugInProc: Running";
47 * Initializate the speech plugin.
49 bool PlugInProc::init(KConfig
* /*config*/, const QString
& /*configGroup*/){
50 // kDebug() << "PlugInProc::init: Running";
55 * Say a text. Synthesize and audibilize it.
56 * @param text The text to be spoken.
58 * If the plugin supports asynchronous operation, it should return immediately.
60 void PlugInProc::sayText(const QString
& /*text*/){
61 // kDebug() << "PlugInProc::sayText: Running";
65 * Synthesize text into an audio file, but do not send to the audio device.
66 * @param text The text to be synthesized.
67 * @param suggestedFilename Full pathname of file to create. The plugin
68 * may ignore this parameter and choose its own
69 * filename. KTTSD will query the generated
70 * filename using getFilename().
72 * If the plugin supports asynchronous operation, it should return immediately.
74 void PlugInProc::synthText(const QString
& /*text*/, const QString
& /*suggestedFilename*/) { }
77 * Get the generated audio filename from synthText.
78 * @return Name of the audio file the plugin generated.
79 * Null if no such file.
81 * The plugin must not re-use the filename.
83 QString
PlugInProc::getFilename() { return QString(); }
86 * Stop current operation (saying or synthesizing text).
87 * This function only makes sense in asynchronus modes.
88 * The plugin should return to the psIdle state.
90 void PlugInProc::stopText(){
91 // kDebug() << "PlugInProc::stopText: Running";
95 * Return the current state of the plugin.
96 * This function only makes sense in asynchronous mode.
97 * @return The pluginState of the plugin.
101 pluginState
PlugInProc::getState() { return psIdle
; }
104 * Acknowledges a finished state and resets the plugin state to psIdle.
106 * If the plugin is not in state psFinished, nothing happens.
107 * The plugin may use this call to do any post-processing cleanup,
108 * for example, blanking the stored filename (but do not delete the file).
109 * Calling program should call getFilename prior to ackFinished.
111 void PlugInProc::ackFinished() { }
114 * Returns True if the plugin supports asynchronous processing,
115 * i.e., returns immediately from sayText or synthText.
116 * @return True if this plugin supports asynchronous processing.
118 bool PlugInProc::supportsAsync() { return false; }
121 * Returns True if the plugin supports synthText method,
122 * i.e., is able to synthesize text to a sound file without
123 * audibilizing the text.
124 * @return True if this plugin supports synthText method.
126 bool PlugInProc::supportsSynth() { return false; }
129 * Returns the name of an XSLT stylesheet that will convert a valid SSML file
130 * into a format that can be processed by the synth. For example,
131 * The Festival plugin returns a stylesheet that will convert SSML into
132 * SABLE. Any tags the synth cannot handle should be stripped (leaving
133 * their text contents though). The default stylesheet strips all
134 * tags and converts the file to plain text.
135 * @return Name of the XSLT file.
137 QString
PlugInProc::getSsmlXsltFilename()
139 return KGlobal::dirs()->resourceDirs("data").last() + "kttsd/xslt/SSMLtoPlainText.xsl";
143 * Given the name of a codec, returns the QTextCodec for the name.
144 * Handles the following "special" codec names:
145 * Local The user's current Locale codec.
146 * Latin1 Latin1 (ISO 8859-1)
148 * @param codecName Name of desired codec.
149 * @return The codec object. Calling program must not delete this object
150 * as it is a reference to an existing QTextCodec object.
152 * Caution: Do not pass translated codec names to this routine.
154 /*static*/ QTextCodec
* PlugInProc::codecNameToCodec(const QString
&codecName
)
156 QTextCodec
* codec
= 0;
157 if (codecName
== "Local")
158 codec
= QTextCodec::codecForLocale();
159 else if (codecName
== "Latin1")
160 codec
= QTextCodec::codecForName("ISO8859-1");
161 else if (codecName
== "Unicode")
162 codec
= QTextCodec::codecForName("utf16");
164 codec
= QTextCodec::codecForName(codecName
.toLatin1());
167 kDebug() << "PluginProc::codecNameToCodec: Invalid codec name " << codecName
;
168 kDebug() << "PluginProc::codecNameToCodec: Defaulting to ISO 8859-1";
169 codec
= QTextCodec::codecForName("ISO8859-1");
175 * Builds a list of codec names, suitable for display in a QComboBox.
176 * The list includes the 3 special codec names (translated) at the top:
177 * Local The user's current Locale codec.
178 * Latin1 Latin1 (ISO 8859-1)
181 /*static*/ QStringList
PlugInProc::buildCodecList()
183 // kDebug() << "PlugInConf::buildCodecList: Running";
184 QStringList codecList
;
185 QString local
= i18nc("Local charset", "Local")+" (";
186 local
+= QTextCodec::codecForLocale()->name();
188 codecList
.append(local
);
189 codecList
.append(i18nc("Latin charset", "Latin1"));
190 codecList
.append(i18n("Unicode"));
191 QList
<QByteArray
> availableCodecs
= QTextCodec::availableCodecs();
192 for (int i
= 0; i
< availableCodecs
.size(); ++i
)
193 codecList
.append(availableCodecs
.at(i
));
198 * Given the name of a codec, returns index into the codec list.
199 * Handles the following "special" codec names:
200 * Local The user's current Locale codec.
201 * Latin1 Latin1 (ISO 8859-1)
203 * @param codecName Name of the codec.
204 * @param codecList List of codec names. The first 3 entries may be translated names.
205 * @return QTextCodec object. Caller must not delete this object.
207 * Caution: Do not pass translated codec names to this routine in codecName parameter.
209 /*static*/ int PlugInProc::codecNameToListIndex(const QString
&codecName
, const QStringList
&codecList
)
212 if (codecName
== "Local")
213 codec
= PlugInProc::Local
;
214 else if (codecName
== "Latin1")
215 codec
= PlugInProc::Latin1
;
216 else if (codecName
== "Unicode")
217 codec
= PlugInProc::Unicode
;
219 codec
= PlugInProc::Local
;
220 const uint codecListCount
= codecList
.count();
221 for (uint i
= PlugInProc::UseCodec
; i
< codecListCount
; ++i
)
222 if (codecName
== codecList
[i
])
229 * Given index into codec list, returns the codec object.
230 * @param codecNum Index of the codec.
231 * @param codecList List of codec names. The first 3 entries may be translated names.
232 * @return QTextCodec object. Caller must not delete this object.
234 /*static*/ QTextCodec
* PlugInProc::codecIndexToCodec(int codecNum
, const QStringList
&codecList
)
236 QTextCodec
* codec
= 0;
238 case PlugInProc::Local
:
239 codec
= QTextCodec::codecForLocale();
241 case PlugInProc::Latin1
:
242 codec
= QTextCodec::codecForName("ISO8859-1");
244 case PlugInProc::Unicode
:
245 codec
= QTextCodec::codecForName("utf16");
248 codec
= QTextCodec::codecForName(codecList
[codecNum
].toLatin1());
253 kDebug() << "PlugInProc::codecIndexToCodec: Invalid codec index " << codecNum
;
254 kDebug() << "PlugInProc::codecIndexToCodec: Defaulting to ISO 8859-1";
255 codec
= QTextCodec::codecForName("ISO8859-1");
261 * Given index into codec list, returns the codec Name.
262 * Handles the following "special" codec names:
263 * Local The user's current Locale codec.
264 * Latin1 Latin1 (ISO 8859-1)
266 * @param codecNum Index of the codec.
267 * @param codecList List of codec names. The first 3 entries may be translated names.
268 * @return Untranslated name of the codec.
270 /*static*/ QString
PlugInProc::codecIndexToCodecName(int codecNum
, const QStringList
&codecList
)
274 case PlugInProc::Local
:
277 case PlugInProc::Latin1
:
278 codecName
= "Latin1";
280 case PlugInProc::Unicode
:
281 codecName
= "Unicode";
284 if (codecNum
< codecList
.count())
285 codecName
= codecList
[codecNum
];
288 kDebug() << "PlugInProc::codecIndexToCodec: Invalid codec index " << codecNum
;
289 kDebug() << "PlugInProc::codecIndexToCodec: Defaulting to ISO 8859-1";
290 codecName
= "ISO8859-1";