轉摘地址:http://qt.csdn.net/articles.aspx?pointid=930&pointid2=
想要多瞭解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