Qt5 朗读语音
在.pro文件中添加
bash
QT += texttospeech
LIBS += -lole32

main.cpp
bash
#include "mainwindow.h"
#include <QApplication>
#include <windows.h>
#include <sapi.h>
#include <sphelper.h>
#include <QDebug>
#include <QTextToSpeech>
void speakQt(const QString &text) {
QTextToSpeech *speech = new QTextToSpeech();
if (speech->availableVoices().isEmpty()) {
qDebug() << "No TTS voices available";
return;
}
speech->say(text);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
QString text="出现告警,请关注";
speakQt(text);
return a.exec();
}
可以听到朗读的声音
