您的位置:首页 > 编程语言 > Qt开发

WIN7下使用Qt调用微软TTS进行文本朗读

2011-09-02 17:32 579 查看
最近研究了下调用微软TTS引擎进行朗读的相关资料,发现其实很简单,特发文与众位博友共享。

首先看看微软MSDN官方文档是如何调用TTS的

Win7TTSWin7TTS::Win7TTS(void) :
_binit(0),
_bReading(0)
{
}

Win7TTS::~Win7TTS(void)
{
}

bool Win7TTS::initSpeech()
{

if(_binit)
return true;

_binit = this->_voice.setControl("96749377-3391-11D2-9EE3-00C04F797396");

if(_binit)
{
connect(&this->_voice,SIGNAL(signal(QString, int, void*)), this, SLOT(dealevent(QString, int, void*)));
}

return _binit;
}

bool Win7TTS::speak(QString & txt)
{
if(!_binit)
return false;

int result = this->_voice.dynamicCall("Speak(QString, SpeechVoiceSpeakFlags)", txt ,1).toInt();
_bReading = true;
return result;
}

void Win7TTS::pause()
{
if(!_binit)
return;
_bReading = false;
this->_voice.dynamicCall("Pause()");
}

void Win7TTS::resume()
{
if(!_binit)
return;
_bReading = true;
this->_voice.dynamicCall("Resume()");
}

void Win7TTS::stop()
{
if(!_binit)
return;
_bReading = false;
int result = this->_voice.dynamicCall("Speak(QString, SpeechVoiceSpeakFlags)", "" ,2).toInt();
}

bool Win7TTS::isSpeaking()
{
return _bReading;
}

//rate range : -10 - 10
int Win7TTS::rate()
{
if(!_binit)
return -99999;

return this->_voice.property("Rate").toInt();
}

void Win7TTS::setRate(int rate)
{
if(!_binit)
return;

this->_voice.dynamicCall("SetRate(int)", rate);
}

//volume range : 0 - 100
int Win7TTS::volume()
{

if(!_binit)
return -99999;

return this->_voice.property("Volume").toInt();
}

void Win7TTS::setVolume(int value)
{
if(!_binit)
return;

this->_voice.dynamicCall("SetVolume(int)", value);
}

void Win7TTS::dealevent(QString name, int arc , void* argv)
{
if(name == "EndStream(int,QVariant)")
{
_bReading = false;
emit speakComplete();
}
}

TTS的框架已经搭好了,现在让我们试试TTS的魅力吧,稍后上传一个TTS的SAMPLE,可以下载下来玩玩!





Win7 TTS 示例
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: