#include <QApplication>#include <QDebug>#include <QTextCodec>#include <QTime>QString textInDoubleQuotes(QString text){ return QString('"' + text + '"');}int main(int argc, char *argv[]){ QApplication a(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("windows-1251")); QString pathToTTS = QApplication::applicationDirPath() + QDir::separator() + "espeak.exe"; QString lang; QString text; lang = " -ven "; text = textInDoubleQuotes("Current time: " + QTime::currentTime().toString("h") + " hours " + QTime::currentTime().toString("m") + " minutes " + QTime::currentTime().toString("s") + " seconds");/* lang = " -vru "; text = textInDoubleQuotes(QObject::tr("Текущее время:") + QTime::currentTime().toString("h") + QObject::tr(" часов ") + QTime::currentTime().toString("m") + QObject::tr(" минут ") + QTime::currentTime().toString("s") + QObject::tr(" секунд"));*/ QProcess proc; proc.start(pathToTTS + lang + text, QIODevice::WriteOnly); if(!proc.waitForStarted()) { qDebug() << "Error starting process: " << proc.errorString(); return -1; } proc.waitForReadyRead(); proc.close();}
#include <QtGui/QApplication>#include <QProcess>int main(int argc, char *argv[]){ QApplication a(argc, argv); QString pathToTTS = QApplication::applicationDirPath() + "\\" + "espeak.exe"; QString text = QString(argv[1]) + " " + QString(argv[2]) + " " + QString(argv[3]); QProcess *processSpeak = new QProcess(); processSpeak->start(pathToTTS + " " + text, QIODevice::WriteOnly); processSpeak->waitForReadyRead(); return 0;}
void Widget::speak(){ // если textedit не пуст if(!textEdit->toPlainText().isEmpty()) { QString pathToTTS = QApplication::applicationDirPath() + QDir::separator() + "ServiceEspeak.exe "; QString text; // если есть выделенный текст if(!textEdit->textCursor().selectedText().isEmpty()) text = textInDoubleQuotes(textEdit->textCursor().selectedText()); else // иначе весь текст text = textInDoubleQuotes(textEdit->toPlainText()); QString pathToFile = QApplication::applicationDirPath() + QDir::separator() + "temp.txt"; QFile::remove(pathToFile); QFile file(pathToFile); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out.setCodec("utf-8"); out << text; file.close(); processSpeak = new QProcess(this); processSpeak->startDetached(pathToTTS + " -vru -f " + pathToFile); processSpeak->waitForReadyRead(); processSpeak->close(); delete processSpeak; processSpeak = 0; }}