Why http request returned empty

1 view (last 30 days)
raym
raym on 26 Nov 2018
Commented: raym on 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 Comment
raym
raym on 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":[]}

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!