为了简便起见,工程里只有一个main.cpp文件,不要忘了在.pro文件中加入下面两行:
QT += multimedia CONFIG += qaxcontainer
下面给出main.cpp文件:
#include "widget.h"
#include <QApplication>
#include<QtMultimedia/QMediaPlayer>
#include<QUrl>
#include<ActiveQt/QAxObject>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMediaPlayer *player = new QMediaPlayer();
player->setMedia(QUrl("http://media.shanbay.com/audio/us/hello.mp3"));
player->play();
QAxObject *speech= new QAxObject();
speech->setControl("SAPI.SpVoice");
speech->dynamicCall("Speak(QString,uint)","good",1);//这里换成中文也可以
return a.exec();
}
运行后,你会发现本地发音肯定没网络发音好,本地发音是电脑发音,这也是缺点之一。原文地址:http://blog.csdn.net/tengweitw/article/details/38555787