【发布时间】:2014-09-27 19:27:00
【问题描述】:
我想使用谷歌语音 api,我发现这个 https://github.com/gillesdemey/google-speech-v2/ 解释得很好,但是我试图将它重写成 java。
File filetosend = new File(path);
byte[] bytearray = Files.readAllBytes(filetosend);
URL url = new URL("https://www.google.com/speech-api/v2/recognize?output="+outputtype+"&lang="+lang+"&key="+key);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//method
conn.setRequestMethod("POST");
//header
conn.setRequestProperty("Content-Type", "audio/x-flac; rate=44100");
现在我迷路了...我想我需要将字节数组添加到请求中。在示例中它的行
--data-binary @audio/good-morning-google.flac \
但是 httpurlconnection 类没有附加二进制数据的方法。
【问题讨论】:
标签: java post google-api httpurlconnection binary-data