Qt5 朗读语音

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();
}

可以听到朗读的声音

相关推荐
恣艺几秒前
Python 游戏开发与文件处理:PyGame + Turtle + openpyxl + python-docx + PyPDF2
开发语言·python·pygame
高林雨露8 分钟前
kotlin 相关code
开发语言·kotlin
我还记得那天11 分钟前
函数的递归调用
c语言·开发语言·visualstudio
zhangfeng113311 分钟前
ThinkPHP5 事件系统的标准最佳实践 事件系统的完整设计逻辑tags.php tags.php(事件地图)
android·开发语言·php
xyq202415 分钟前
HTML 标签简写及全称
开发语言
tongluowan00716 分钟前
数据结构 Bitmap(位图)示例 - 用户签到系统
开发语言·数据结构·bitmap·用户签到系统
就叫_这个吧16 分钟前
Java线程池应用的四种方式+线程池底层实现原理
java·开发语言
Rust研习社18 分钟前
Rust 官方拟定 LLM 政策,防止 LLM 污染开源社区?
开发语言·后端·ai·rust·开源
muqsen20 分钟前
Java 分布式相关面试题总结
java·开发语言·分布式
fenglllle30 分钟前
JDK8升级JDK17使用CompletableFuture在线程中classloader的变化
java·开发语言·jvm