第一范文网 - 专业文章范例文档资料分享平台

qt 操作tts (3)

来源:用户分享 时间:2020-06-22 本文由妖艳的兔子 分享 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

releaseFunc = (ReleaseFunc)lib.resolve(\); speakFunc = (SpeakFunc)lib.resolve(\);

if (initializeFunc && releaseFunc && speakFunc) { initializeFunc(); ttsLoaded = true;

qDebug() << \;

// When tts is loaded, initialize the speak thread.

speakThread = new SpeakThread(this);

speak(\); // 加载完后说一下,准备好,因为第一次说都会很慢

} } else {

qDebug() << lib.errorString(); } }

void Speaker::removeTts() {

// If tts is not loaded, removing process is not needed.

if (!ttsLoaded) { return; }

releaseFunc();

ttsLoaded = false; initializeFunc = 0; releaseFunc = 0; speakFunc = 0;

qDebug() << \;

// After tts is removed, speak thread is also need to be removed.

if (speakThread != 0) { speakThread->terminate(); }

delete speakThread; speakThread = 0; } /**

* After the process that loads tts is completed, the load thread is not needed, then remove it. */

void Speaker::completeLoadTts() {

delete ttsLoader; ttsLoader = 0; } /**

* After the process that removes tts is completed, the remove thread is not needed, then remove it. */

void Speaker::completeRemoveTts() {

delete ttsRemover; ttsRemover = 0; } /**

* Terminated all threads. */

void Speaker::terminateAllThreads() {

if (ttsLoader != 0) { ttsLoader->terminate(); }

if (ttsRemover != 0) { ttsRemover->terminate(); }

if (speakThread != 0) { speakThread->terminate(); } }

/////////////////////////////////////////////////////////////////////////////////// TtsLoader::TtsLoader(Speaker *speaker) { this->speaker = speaker; stopped = false; }

void TtsLoader::run() {

if (!stopped) { speaker->loadTts(); }

stopped = false; // }

void TtsLoader::stop() {

stopped = true;

}

/////////////////////////////////////////////////////////////////////////////////// TtsRemover::TtsRemover(Speaker *speaker) { this->speaker = speaker; stopped = false; }

void TtsRemover::run() {

if (!stopped) {

speaker->removeTts(); }

stopped = false; }

void TtsRemover::stop() {

stopped = true; }

/////////////////////////////////////////////////////////////////////////////////// SpeakThread::SpeakThread(Speaker *speaker) { this->speaker = speaker; stopped = false; }

void SpeakThread::run() {

if (!stopped) {

speaker->speakString(speakingString); }

stopped = false; }

void SpeakThread::stop() {

stopped = true; }

void SpeakThread::setSpeakingString(const QString &speakingString) {

this->speakingString = speakingString; } /*

很奇怪的问题: 如果直接使用loadTts()和removeTts()函数来初始化和释放TTS的资源, 就不会存在内存泄漏问题. 但是如果使用线程来处理, 即调用initializeTts(), releaseTts(), 在线程中调用loadTts(), removeTts()来初始化和释放TTS的资源, 就会存在内存泄漏. 泄漏的内存大小为初始化一次TTS的内存, 没发现会叠加.

文本发音的使用过程: 由于使用的是单态模式, 所以在使用发音函数speak前, 初始化TTS一次就可以了, 而TTS的资源释放是自动释放的, 当然也可以手动释放.

1. Speaker::getInstance().initializeTts(); // 最好程序启动的时候调用. 2. Speaker::getInstance().speak(str);

.................可以在程序的任何地方直接调用.(如果TTS没有被加载, 或者不启用语音功能, 这时调用了不起任何作用)

[不需要自己手动释放TTS的资源, 因为使用了智能指针实现单态模式] */

搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新幼儿教育qt 操作tts (3)全文阅读和word下载服务。

qt 操作tts (3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/wenku/1097106.html(转载请注明文章来源)
热门推荐
Copyright © 2018-2022 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top