码迷,mamicode.com
首页 > 其他好文 > 详细

QtSpeech会让Qt说话

时间:2014-08-29 10:46:27      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:http   os   使用   io   strong   ar   for   文件   div   

想要多了解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

  1. <blockquote>#include <QtSpeech> 
  2. …  
  3. QtSpeech voice;  
  4. voice.say(“Hello World!”); 

如果是异步调用(发音不会阻塞程序运行),则可以使用QtSpeech::tell

  1. <blockquote>#include <QtSpeech> 
  2. …  
  3. QtSpeech * voice = new QtSpeech(this);  
  4. voice->tell(“Hello asynchronous world!”);  

如果使用QtSpeech::tell,还可以加入slot函数,在发音结束时回调该slot

  1. voice->tell(“Hello!”, this, SLOT(onSpeechFinished()));  

VoiceName可以用于设定发音类型的,比如英语或者法语,意大利语等

  1. QtSpeech::VoiceNames vs = QtSpeech::voices(); 

//不过,目前从源代码来看只支持英语

在ubuntu下编译

  1. $ #qtspeech 依赖的tts是festival,所以需要先安装  
  2. $ sudo apt-get install festival festival-dev  
  3. $ sudo apt-get install libasound2-dev  
  4. $ git clone git://gitorious.org/qt-speech/qt-speech.git  
  5. $ cd qt-speech/  
  6. $ qmake QtSpeech.pro  
  7. $ make  
  8. $ #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

QtSpeech会让Qt说话

标签:http   os   使用   io   strong   ar   for   文件   div   

原文地址:http://www.cnblogs.com/lvdongjie/p/3944183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!