QNetworkAccessManager download mp3 file
-
I have a code
@void Eng::getRecord(QString& file, QString& word)
{
QEventLoop loop;
req.setUrl(QUrl("http://translate.google.ru/translate_tts?ie=UTF-8&q=" + word + "&tl=en&total=1&idx=0&textlen=" + word.length() + "&prev=input"));
QNetworkReply* reply = m->get(req);
QObject::connect(reply,SIGNAL(finished()),&loop,SLOT(quit()));
loop.exec();
QFile out(file);
out.open(QIODevice::Text | QIODevice::WriteOnly);
QTextStream stream(&out);
stream << reply->readAll();
out.close();
}@
File was saved, but in incorrect format. Can i save in correct format that file? -
Try the same code just omitting the "QIODevice::Text" mode.
-
If you don't mind, can you show the complete URL that you have passed ?
-
Use that for example http://kibergard.com/cache/music/3ea/853372/Selena Gomez - Come and Get It (Fred Falke Dub).mp3
-
Instead of passing it to QTextStream write the QByteArray directly to QFile.
For eg.
Following works for me:@QEventLoop loop;
QNetworkRequest req;
QNetworkAccessManager m = new QNetworkAccessManager;
req.setUrl(QUrl("http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=hello+world"));
QNetworkReply reply = m->get(req);
QObject::connect(reply,SIGNAL(finished()),&loop,SLOT(quit()));
loop.exec();QFile out("/root/Speech/hello.mp3"); out.open(QIODevice::WriteOnly); //QTextStream stream(&out); //stream << reply->readAll(); out.write(reply->readAll()); out.close();@