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 Center および File ExchangeCall 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