Why http request returned empty

1 次查看(过去 30 天)
raym
raym 2018-11-26
评论: raym 2018-11-26
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 个评论
raym
raym 2018-11-26
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":[]}

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Web Services from MATLAB Using HTTP 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by