File indexing completed on 2024-05-19 03:42:58

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 <QStringConverter>
0027 #include <QTemporaryFile>
0028 
0029 /**This class is used internally by TextToSpeechSystem in order to do the actual speaking.
0030  *@author Gunnar Schmi Dt
0031  */
0032 
0033 class Speech : public QObject
0034 {
0035     Q_OBJECT
0036 public:
0037     enum CharacterCodec { Local = 0, Latin1 = 1, Unicode = 2, UseCodec = 3 };
0038 
0039     Speech();
0040     ~Speech() override;
0041 
0042     /**
0043      * Speaks the given text.
0044      * @param command the program that shall be executed for speaking
0045      * @param stdin true if the program shall receive its data via standard input
0046      * @param text The text that shall be spoken
0047      * @param language the language to use when speaking
0048      * @param encoding the encoding to use to decode the text
0049      */
0050     void speak(QString command, bool use_stdin, const QString &text, const QString &language, QStringConverter::Encoding encoding);
0051 
0052     /**
0053      * Prepares a command for being executed. During the preparation the
0054      * command is parsed and occurrences of "%t" are replaced by text.
0055      * @param command the command that shall be executed for speaking
0056      * @param text the quoted text that can be inserted into the command
0057      */
0058     QString prepareCommand(const QString &command, const QString &text, const QString &filename, const QString &language);
0059 
0060 public Q_SLOTS:
0061     // void wroteStdin(K3Process *p);
0062     void processExited(int exitCode, QProcess::ExitStatus exitStatus);
0063     // void receivedStdout(K3Process *proc, char *buffer, int buflen);
0064     // void receivedStderr(K3Process *proc, char *buffer, int buflen);
0065 
0066 private:
0067     QProcess m_process;
0068     QByteArray encText;
0069     QTemporaryFile tempFile;
0070 };
0071 
0072 #endif