我想使用Google语音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");
现在我迷失了方向... 我猜我需要将bytearray添加到请求中。 在例子中是这一行:
--data-binary @audio/good-morning-google.flac \
但是HttpURLConnection类没有附加二进制数据的方法。