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

可以听到朗读的声音

相关推荐
阿里嘎多学长2 小时前
2026-04-30 GitHub 热点项目精选
开发语言·程序员·github·代码托管
叶小鸡3 小时前
Java 篇-项目实战-苍穹外卖-笔记汇总
java·开发语言·笔记
AI人工智能+电脑小能手3 小时前
【大白话说Java面试题】【Java基础篇】第22题:HashMap 和 HashSet 有哪些区别
java·开发语言·哈希算法·散列表·hash
时空系4 小时前
第10篇:继承扩展——面向对象编程进阶 python中文编程
开发语言·python·ai编程
CHANG_THE_WORLD5 小时前
python 批量终止进程exe
开发语言·python
古城小栈5 小时前
从 cargo-whero 库中,找到提升 rust 的契机
开发语言·后端·rust
Gary Studio7 小时前
安卓HAL C++基础-智能指针
开发语言·c++
啧不应该啊7 小时前
Day1 Python 与 C 的类型区别
c语言·开发语言
cen__y7 小时前
Linux07(信号01)
linux·运维·服务器·c语言·开发语言
xingpanvip8 小时前
星盘接口开发文档:星相日历接口指南
android·开发语言·前端·css·php·lua