Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager download mp3 file
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager download mp3 file

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bagipro
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Try the same code just omitting the "QIODevice::Text" mode.

      157

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bagipro
        wrote on last edited by
        #3

        Still doesn't work

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          If you don't mind, can you show the complete URL that you have passed ?

          157

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bagipro
            wrote on last edited by
            #5

            Use that for example http://kibergard.com/cache/music/3ea/853372/Selena Gomez - Come and Get It (Fred Falke Dub).mp3

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              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();@
              

              157

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bagipro
                wrote on last edited by
                #7

                @out.open(QIODevice::WriteOnly);
                out.write(reply->readAll());
                out.close();@

                Yes! Thats work!1 Thank you!

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved