Binary file download using QT
I newbie in QT programming and one of my tools needs a feature to get the audio translation of a text line using google translate api.The easiest solution was to use a special URL Google(http://translate.google.com/translate_tts?tl=en&q="...my string..."). Using wget tool a did that by this way :
cd google_has_you && wget -m -k -U "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8" "http://translate.google.com/translate_tts?tl=en&q=in+soviet+russia+games+plays+you"
and then i renamed downloaded file to test.mp3 to check audio translation
teddy@Desktop:~/google_has_you/translate.google.com$ mv * test.mp3
My question is how to do it with Qt,that is, how to do开发者_开发技巧wnload a binary file (mp3) from url : http://translate.google.com/translate_tts?tl=en&q=" + my text, and then to play downloaded using Phonon.
You can either use QNetworkAccessManager to download the file and then play it by passing the path to the local file to the Phonon media source, or let Phonon stream it. A code snippet (url is a QUrl) (Everything on the stack because I copied it from a main()):
MediaSource src( url );
MediaObject obj;
obj.setCurrentSource( src );
AudioOutput audio( VideoCategory );
Phonon::createPath( &obj, &audio );
obj.play();
精彩评论