QtSpeech会让Qt说话
想要多了解QtSpeech,那么随着本文的文字往下走吧!QtSpeech是一个Qt封装的跨平台TTS(文本变成语音输出)API,在不同平台下利用系统自带的TTS引擎。在Windows下使用SAPI, 在Mac下使用SpeechSynthesis,而在Linux下使用 Festival.
QtSpeech的官方项目主页在: http://lynxline.com/projects/qtspeech
源码git仓库地址则在: http://gitorious.org/qt-speech
API的使用非常简单,如果你是同步调用,发音结束后返回,可以使用QtSpeech::say
- <blockquote>#include <QtSpeech>
- …
- QtSpeech voice;
- voice.say(“Hello World!”);
如果是异步调用(发音不会阻塞程序运行),则可以使用QtSpeech::tell
- <blockquote>#include <QtSpeech>
- …
- QtSpeech * voice = new QtSpeech(this);
- voice->tell(“Hello asynchronous world!”);
如果使用QtSpeech::tell,还可以加入slot函数,在发音结束时回调该slot
- voice->tell(“Hello!”, this, SLOT(onSpeechFinished()));
VoiceName可以用于设定发音类型的,比如英语或者法语,意大利语等
- QtSpeech::VoiceNames vs = QtSpeech::voices();
//不过,目前从源代码来看只支持英语
在ubuntu下编译
- $ #qtspeech 依赖的tts是festival,所以需要先安装
- $ sudo apt-get install festival festival-dev
- $ sudo apt-get install libasound2-dev
- $ git clone git://gitorious.org/qt-speech/qt-speech.git
- $ cd qt-speech/
- $ qmake QtSpeech.pro
- $ make
- $ #test
目录下有可以测试的例子,记得把音箱打开
小结:QtSpeech就介绍到这里吧,注意了,头文件得自己手动添加,如果还出错的话,那就是你没装Qt开发包!!!不要饭低级错误哦。
QtSpeech, say “Hello World!”
I am glad to announce new small project that got first release – QtSpeech.
This is library providing Qt-like interface to system TTS (text-to-speech) engines to allow your application to say “Hello World!”.
Current API is very simple.
First you need to include <QtSpeech>. Then if your application just needed to say something synchronously (execution will wait in the point until speech is finished) you can use such code:
1 |
#include <QtSpeech> |
2 |
|
3 |
QtSpeech voice; |
4 |
voice.say( "Hello World!" ); |
If you would like to do this in asynchronous way (so your application is not blocked meanwhile) just use tell() call:
1 |
QtSpeech * voice = new QtSpeech( this ); |
2 |
voice->tell( "Hello asynchronous world!" ); |
If you need to invoke a slot at the end, use:
1 |
voice->tell( "Hello!" , this , SLOT(onSpeechFinished())); |
Also you have possibility to get list of voices and choose voice from available in your system:
1 |
QtSpeech::VoiceNames vs = QtSpeech::names() |
Current implementation support Windows using SAPI and Mac. I have plans to extend API to include more functionality but will try to choose what is common on all platforms.
Link to repository in Gitorius: http://gitorious.org/qt-speech
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人