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