Qt5 朗读语音
在.pro文件中添加
QT+=texttospeech LIBS+=-lole32
main.cpp
#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();QStringtext="出现告警,请关注";speakQt(text);returna.exec();}可以听到朗读的声音