QtSpeech會讓Qt說話

 轉摘地址: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

  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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章