URL url = new URL("https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=mykey");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "audio/x-flac; rate=16000");
conn.setUseCaches(false);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.write(bytearray);
wr.flush();
wr.close();
InputStream stream = conn.getInputStream(); //throws io exception
所以基本上我试图发送bytearray
而不是httpurlconnection
java.io.IOException:在最后一行写入服务器时出错。