gpt4 book ai didi

java - 使用 HttpURLConnection 发送二进制数据

转载 作者:行者123 更新时间:2023-11-30 07:06:00 25 4
gpt4 key购买 nike

我想使用谷歌语音 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 类没有附加二进制数据的方法。

最佳答案

但它有 getOutputStream(),您可以向其中写入数据。您可能还想调用 setDoOutput(true)

关于java - 使用 HttpURLConnection 发送二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26078344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com