Results 1 to 1 of 1

Thread: Google cloud synchronous speech using local file

  1. #1
    Join Date
    Apr 2017
    Posts
    2
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Google cloud synchronous speech using local file

    Hi everyone,

    I have a problem with google speech implementation in Qt (local audio file from my PC).
    I got QtNetwork reply as network error(contentNotFoundError). google error string received as "Error transferring https://speech.googleapis.com/v1/spe...nize?key=mykey - server replied: Not Found".
    My Qt code is below.
    Any help is appreciated.
    Qt Code:
    1. PrepareJsonAndPost()
    2. {
    3. QString path = QCoreApplication::applicationDirPath() + "/" + "testAudio.wav";
    4. QFile file(path);
    5. bool fileOpenStatus = file.open(QIODevice::ReadOnly);
    6. QByteArray byteArray = file.readAll();
    7. QString jsonData = byteArray.toBase64();
    8. convertAudioToSpeech(jsonData);
    9. }
    10.  
    11. //Json request Post to google cloud
    12. convertAudioToSpeech(QString jsonData)
    13. {
    14. QNetworkRequest request(QUrl("https://speech.googleapis.com/v1/speech:recognize?key=myAPIKey"));
    15. request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    16. QLoggingCategory::setFilterRules("qt.network.ssl.w arning=false");
    17. QJsonObject jsonObject;
    18. QJsonObject configObject;
    19. configObject.insert("encoding", "LINEAR16");
    20. configObject.insert("sampleRateHertz", 16000);
    21. configObject.insert("languageCode", "en-US");
    22. jsonObject.insert("config",configObject);
    23. QJsonObject audioObject;
    24. audioObject.insert("content", jsonData);
    25. jsonObject.insert("audio",audioObject);
    26.  
    27. QNetworkAccessManager *nam = new QNetworkAccessManager(this);
    28.  
    29. QJsonDocument jsonDoc(jsonObject);
    30. QByteArray jsonBytes = jsonDoc.toJson();
    31. QNetworkReply *reply;
    32. //QEventLoop loop;
    33. reply= nam->post(request, jsonBytes);
    34.  
    35. while (!reply->isFinished()) {
    36. qApp->processEvents();
    37.  
    38. }
    39.  
    40. if (reply->error() == QNetworkReply::NoError)
    41. {
    42. QByteArray response_data = reply->readAll();
    43. QJsonDocument document = QJsonDocument::fromJson(response_data);
    44. qDebug() << "OutPut : " << document.toJson(QJsonDocument::Compact);
    45. }
    46. else // something went wrong
    47. {
    48. qDebug() << "Json File Failed to Load : " << filename;
    49. qDebug() << "Error : " << reply->errorString();
    50. qDebug() << "Error Code : " << reply->error();
    51. }
    52.  
    53. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by sivaprasad1984; 24th April 2017 at 08:06.

Similar Threads

  1. Google cloud Streaming Speech recognition using Qt
    By sivaprasad1984 in forum Qt Programming
    Replies: 1
    Last Post: 20th April 2017, 22:11
  2. Replies: 2
    Last Post: 7th November 2015, 23:46
  3. Google Cloud Messanging in Qt QMl
    By sosto in forum Qt Quick
    Replies: 1
    Last Post: 28th January 2015, 10:34
  4. Replies: 1
    Last Post: 22nd December 2010, 17:56
  5. linking a google protobuf file and a QT file
    By pratikag in forum Newbie
    Replies: 2
    Last Post: 29th June 2010, 18:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.