Why http request returned empty

4 Ansichten (letzte 30 Tage)
raym
raym am 26 Nov. 2018
Kommentiert: raym am 26 Nov. 2018
I write the code to send a binary data of an recorded speech audio "tmphpzsjbv7.flac" file to Google speech website to get the text of the speech:
URL = 'http://www.google.com/speech-api/v2/recognize?client=chromium&lang=zh-CN&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw';
filename = 'D:\QMDownload\1\tmphpzsjbv7.flac';
fid = fopen(filename,'r+');
data1 = uint8(fread(fid))';
fclose(fid);
header = matlab.net.http.field.ContentTypeField('audio/x-flac; rate=16000');
data = char(data1);
req = matlab.net.http.RequestMessage('POST',header,data);
uri = matlab.net.URI(URL);
resp = req.send(uri);
resp.Body.Data.result % always is []
When I run the equivalent code in py module of matlab using the requests lib imported from py, it indeed returns an resp object, and the resp.content field (a very long string) has the recognized speech inside, and I just need to dig it out using regexp.
  1 Kommentar
raym
raym am 26 Nov. 2018
below is the returned resp:
resp.char
ans =
'HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Disposition: attachment
Cache-Control: no-transform
X-Content-Type-Options: nosniff
Pragma: no-cache
Date: Mon, 26 Nov 2018 14:04:20 GMT
Server: S3 v1.0
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close
{"result":[]}

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Call Web Services from MATLAB Using HTTP finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by