File indexing completed on 2023-05-30 10:39:36

0001 /***************************************************************************
0002  *   Copyright (C) 2002 by Gunnar Schmi Dt <kmouth@schmi-dt.de             *
0003  *             (C) 2015 by Jeremy Whiting <jpwhiting@kde.org>              *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
0019  ***************************************************************************/
0020 
0021 #ifndef SPEECH_H
0022 #define SPEECH_H
0023 
0024 #include <QObject>
0025 #include <QProcess>
0026 #include <QTemporaryFile>
0027 
0028 /**This class is used internally by TextToSpeechSystem in order to do the actual speaking.
0029   *@author Gunnar Schmi Dt
0030   */
0031 
0032 class Speech : public QObject
0033 {
0034     Q_OBJECT
0035 public:
0036     enum CharacterCodec {
0037         Local    = 0,
0038         Latin1   = 1,
0039         Unicode  = 2,
0040         UseCodec = 3
0041     };
0042 
0043     Speech();
0044     ~Speech() override;
0045 
0046     /**
0047      * Speaks the given text.
0048      * @param command the program that shall be executed for speaking
0049      * @param stdin true if the program shall receive its data via standard input
0050      * @param text The text that shall be spoken
0051      */
0052     void speak(QString command, bool use_stdin, const QString &text, const QString &language, int encoding, QTextCodec *codec);
0053 
0054     /**
0055      * Prepares a command for being executed. During the preparation the
0056      * command is parsed and occurrences of "%t" are replaced by text.
0057      * @param command the command that shall be executed for speaking
0058      * @param text the quoted text that can be inserted into the command
0059      */
0060     QString prepareCommand(const QString &command, const QString &text,
0061                            const QString &filename, const QString &language);
0062 
0063 public Q_SLOTS:
0064     //void wroteStdin(K3Process *p);
0065     void processExited(int exitCode, QProcess::ExitStatus exitStatus);
0066     //void receivedStdout(K3Process *proc, char *buffer, int buflen);
0067     //void receivedStderr(K3Process *proc, char *buffer, int buflen);
0068 
0069 private:
0070     QProcess m_process;
0071     QByteArray encText;
0072     QTemporaryFile tempFile;
0073 };
0074 
0075 #endif