1 /***************************************************************************
2 hadifixproc.h - description
4 begin : Mon Okt 14 2002
5 copyright : (C) 2002 by Gunnar Schmi Dt
6 email : gunnar@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 #ifndef _HADIFIXPROC_H_
19 #define _HADIFIXPROC_H_
21 #include <QtCore/QStringList>
23 #include <pluginproc.h>
27 class HadifixProcPrivate
;
28 class HadifixProc
: public PlugInProc
{
40 explicit HadifixProc( QObject
* parent
= 0, const QStringList
&args
= QStringList());
45 /** Initializate the speech */
46 virtual bool init (KConfig
*config
, const QString
&configGroup
);
49 * Say a text. Synthesize and audibilize it.
50 * @param text The text to be spoken.
52 * If the plugin supports asynchronous operation, it should return immediately
53 * and emit sayFinished signal when synthesis and audibilizing is finished.
54 * It must also implement the @ref getState method, which must return
55 * psFinished, when saying is completed.
57 virtual void sayText(const QString
&text
);
60 * Synthesize text into an audio file, but do not send to the audio device.
61 * @param text The text to be synthesized.
62 * @param suggestedFilename Full pathname of file to create. The plugin
63 * may ignore this parameter and choose its own
64 * filename. KTTSD will query the generated
65 * filename using getFilename().
67 * If the plugin supports asynchronous operation, it should return immediately
68 * and emit @ref synthFinished signal when synthesis is completed.
69 * It must also implement the @ref getState method, which must return
70 * psFinished, when synthesis is completed.
72 virtual void synthText(const QString
&text
, const QString
&suggestedFilename
);
75 * Get the generated audio filename from call to @ref synthText.
76 * @return Name of the audio file the plugin generated.
77 * Null if no such file.
79 * The plugin must not re-use or delete the filename. The file may not
80 * be locked when this method is called. The file will be deleted when
81 * KTTSD is finished using it.
83 virtual QString
getFilename();
86 * Stop current operation (saying or synthesizing text).
87 * Important: This function may be called from a thread different from the
88 * one that called sayText or synthText.
89 * If the plugin cannot stop an in-progress @ref sayText or
90 * @ref synthText operation, it must not block waiting for it to complete.
91 * Instead, return immediately.
93 * If a plugin returns before the operation has actually been stopped,
94 * the plugin must emit the @ref stopped signal when the operation has
97 * The plugin should change to the psIdle state after stopping the
100 virtual void stopText();
103 * Return the current state of the plugin.
104 * This function only makes sense in asynchronous mode.
105 * @return The pluginState of the plugin.
109 virtual pluginState
getState();
112 * Acknowledges a finished state and resets the plugin state to psIdle.
114 * If the plugin is not in state psFinished, nothing happens.
115 * The plugin may use this call to do any post-processing cleanup,
116 * for example, blanking the stored filename (but do not delete the file).
117 * Calling program should call getFilename prior to ackFinished.
119 virtual void ackFinished();
122 * Returns True if the plugin supports asynchronous processing,
123 * i.e., returns immediately from sayText or synthText.
124 * @return True if this plugin supports asynchronous processing.
126 * If the plugin returns True, it must also implement @ref getState .
127 * It must also emit @ref sayFinished or @ref synthFinished signals when
128 * saying or synthesis is completed.
130 virtual bool supportsAsync();
133 * Returns True if the plugin supports synthText method,
134 * i.e., is able to synthesize text to a sound file without
135 * audibilizing the text.
136 * @return True if this plugin supports synthText method.
138 * If the plugin returns True, it must also implement the following methods:
143 * If the plugin returns True, it need not implement @ref sayText .
145 virtual bool supportsSynth();
148 * Synthesize text using a specified configuration.
149 * @param text The text to synthesize.
150 * @param hadifix Command to run hadifix (txt2pho).
151 * @param isMale True to use male voice.
152 * @param mbrola Command to run mbrola.
153 * @param voice Voice file for mbrola to use.
154 * @param volume Volume percent. 100 = normal
155 * @param time Speed percent. 100 = normal
156 * @param pitch Frequency. 100 = normal
157 * @param waveFilename Name of file to synthesize to.
159 void synth(QString text
,
160 QString hadifix
, bool isMale
,
161 QString mbrola
, QString voice
,
162 int volume
, int time
, int pitch
,
164 const QString waveFilename
);
167 * Static function to determine whether the voice file is male or female.
168 * @param mbrola the mbrola executable
169 * @param voice the voice file
170 * @param output the output of mbrola will be written into this QString*
171 * @return HadifixSpeech::MaleGender if the voice is male,
172 * HadifixSpeech::FemaleGender if the voice is female,
173 * HadifixSpeech::NoGender if the gender cannot be determined,
174 * HadifixSpeech::NoVoice if there is an error in the voice file
176 static VoiceGender
determineGender(QString mbrola
, QString voice
, QString
*output
= 0);
179 * Returns the name of an XSLT stylesheet that will convert a valid SSML file
180 * into a format that can be processed by the synth. For example,
181 * The Festival plugin returns a stylesheet that will convert SSML into
182 * SABLE. Any tags the synth cannot handle should be stripped (leaving
183 * their text contents though). The default stylesheet strips all
184 * tags and converts the file to plain text.
185 * @return Name of the XSLT file.
187 virtual QString
getSsmlXsltFilename();
190 void slotProcessExited(K3Process
*);
191 void slotWroteStdin(K3Process
*);
193 void receivedStdout (K3Process
*, char *buffer
, int buflen
);
194 void receivedStderr (K3Process
*, char *buffer
, int buflen
);
197 HadifixProcPrivate
*d
;