summaryrefslogtreecommitdiffstats
path: root/kttsd/plugins/command/commandproc.h
blob: 694c41f7b6769bb24ca8c0c2aa3636c6ca0cf6dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/***************************************************** vim:set ts=4 sw=4 sts=4:
  Main speaking functions for the Command Plug in
  -------------------
  Copyright : (C) 2002 by Gunnar Schmi Dt and 2004 by Gary Cramblitt
  -------------------
  Original author: Gunnar Schmi Dt <kmouth@schmi-dt.de>
  Current Maintainer: Gary Cramblitt <garycramblitt@comcast.net>
 ******************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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; version 2 of the License.               *
 *                                                                         *
 ***************************************************************************/

#ifndef _COMMANDPROC_H_
#define _COMMANDPROC_H_

// TQt includes.
#include <tqstringlist.h> 

// KTTS includes.
#include <pluginproc.h>

class TDEProcess;
class TQTextCodec;

class CommandProc : public PlugInProc{
    Q_OBJECT
    

    public:
        /** Constructor */
        CommandProc( TQObject* parent = 0, const char* name = 0,
            const TQStringList &args = TQStringList());

        /** Destructor */
        ~CommandProc();

        /** Initializate the speech */
        bool init (TDEConfig *config, const TQString &configGroup);

        /**
         * Say a text string.
         * @param text            The text to speak.
         */
        virtual void sayText(const TQString &text);

        /**
        * Synthesize text into an audio file, but do not send to the audio device.
        * @param text                    The text to be synthesized.
        * @param suggestedFilename       Full pathname of file to create.  The plugin
        *                                may ignore this parameter and choose its own
        *                                filename.  KTTSD will query the generated
        *                                filename using getFilename().
        *
        * If the plugin supports asynchronous operation, it should return immediately.
        */
        virtual void synthText(const TQString& text, const TQString& suggestedFilename);

        /**
        * Get the generated audio filename from synthText.
        * @return                        Name of the audio file the plugin generated.
        *                                Null if no such file.
        *
        * The plugin must not re-use the filename.
        */
        virtual TQString getFilename();

        /**
        * Stop current operation (saying or synthesizing text).
        * Important: This function may be called from a thread different from the
        * one that called sayText or synthText.
        * If the plugin cannot stop an in-progress @ref sayText or
        * @ref synthText operation, it must not block waiting for it to complete.
        * Instead, return immediately.
        *
        * If a plugin returns before the operation has actually been stopped,
        * the plugin must emit the @ref stopped signal when the operation has
        * actually stopped.
        *
        * The plugin should change to the psIdle state after stopping the
        * operation.
        */
        virtual void stopText();

        /**
        * Return the current state of the plugin.
        * This function only makes sense in asynchronous mode.
        * @return                        The pluginState of the plugin.
        *
        * @see pluginState
        */
        virtual pluginState getState();

        /**
        * Acknowledges a finished state and resets the plugin state to psIdle.
        *
        * If the plugin is not in state psFinished, nothing happens.
        * The plugin may use this call to do any post-processing cleanup,
        * for example, blanking the stored filename (but do not delete the file).
        * Calling program should call getFilename prior to ackFinished.
        */
        virtual void ackFinished();

        /**
        * Returns True if the plugin supports asynchronous processing,
        * i.e., returns immediately from sayText or synthText.
        * @return                        True if this plugin supports asynchronous processing.
        *
        * If the plugin returns True, it must also implement @ref getState .
        * It must also emit @ref sayFinished or @ref synthFinished signals when
        * saying or synthesis is completed.
        */
        virtual bool supportsAsync();

        /**
        * Returns True if the plugin supports synthText method,
        * i.e., is able to synthesize text to a sound file without
        * audibilizing the text.
        * @return                        True if this plugin supports synthText method.
        */
        virtual bool supportsSynth();

        /**
        * Say or Synthesize text.
        * @param inputText               The text that shall be spoken
        * @param suggestedFilename       If not Null, synthesize only to this filename, otherwise
        *                                synthesize and audibilize the text.
        * @param userCmd                 The program that shall be executed for speaking
        * @param stdIn                   True if the program shall recieve its data via
        *                                standard input.
        * @param codec                   Codec for encoding the text.
        * @param language                The language code (used for the %l macro)
        */
        void synth(const TQString& inputText, const TQString& suggestedFilename,
            const TQString& userCmd, bool stdIn,
            TQTextCodec *codec, TQString& language);

    private slots:
        void slotProcessExited(TDEProcess* proc);
        void slotReceivedStdout(TDEProcess* proc, char* buffer, int buflen);
        void slotReceivedStderr(TDEProcess* proc, char* buffer, int buflen);
        void slotWroteStdin(TDEProcess* proc);

    private:

        /**
        * True if the plugin supports separate synthesis (option set by user).
        */
        bool m_supportsSynth;

        /**
        * TTS command
        */
        TQString m_ttsCommand;

        /**
        * True if process should use Stdin.
        */
        bool m_stdin;

        /**
        * Language Group.
        */
        TQString m_language;

        /**
        * Codec.
        */
        TQTextCodec* m_codec;

        /**
         * Flite process
         */
        TDEProcess* m_commandProc;

        /**
        * Name of temporary file containing text.
        */
        TQString m_textFilename;

        /**
        * Synthesis filename.
        */
        TQString m_synthFilename;

        /**
        * Plugin state.
        */
        pluginState m_state;

        /**
        * True when stopText has been called.  Used to force transition to psIdle when
        * Flite exits.
        */
        bool m_waitingStop;
};

#endif  // _COMMANDPROC_H_