访问 REST API 时如何处理响应内容类型音频?

How to handle response Content Type Audio when accessing REST API?

我正在使用 Voice RSS 为我的 java 应用程序进行文本到语音的翻译。我过去曾使用像 RESTY 这样的客户端来处理简单的 json 请求,这些请求我觉得很舒服。但在这种情况下,服务器(语音 RSS)返回的内容类型为音频,我不确定如何将其作为 java 客户端处理和解包。任何帮助将不胜感激

谢谢 卡尔提克

我发现您可以使用 Url 和 BufferedInputStream 从 Web 服务下载响应作为字节数组或作为您可以将其保存为任何内容的 OutputStream。

InputStream in = null;
        ByteArrayOutputStream outputStream = null;
        byte[] byteArray = null;
        try {
            URL link = new URL("YOUR_URL");
            in = new BufferedInputStream(link.openStream());
            outputStream = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int n = 0;
            while (-1 != (n = in.read(buf))) {
                outputStream.write(buf, 0, n);
                }
            byteArray = outputStream.toByteArray();
        }catch (Exception ex){
            throw ex;
        }finally {
            if(in != null) in.close();;
            if(outputStream != null) outputStream.close();
        }