https://openapi.youdao.com/ttsapi?q=home&langType=en&sign=4A60FADB46DB69A0C159CC3662A2EF0C&salt=1635078891466&voice=5&format=mp3&appKey=44058feaa2ec7a01&ttsVoiceStrict=false
如何用Java下载下来这个音频文件 已经翻阅大量CDSN没用
如何用Java下载下来这个音频文件 已经翻阅大量CDSN没用
- import java.io.BufferedInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.net.URL;
- public class DownloadFile {
- public static void main(String[] args) {
- String url = "https://openapi.youdao.com/ttsapi?q=home&langType=en&sign=4A60FADB46DB69A0C159CC3662A2EF0C&salt=1635078891466&voice=5&format=mp3&appKey=44058feaa2ec7a01&ttsVoiceStrict=false";
- try {
- download(url, "test.mp3");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static void download(String urlStr, String file) throws IOException{
- URL url = new URL(urlStr);
- BufferedInputStream bis = new BufferedInputStream(url.openStream());
- FileOutputStream fis = new FileOutputStream(file);
- byte[] buffer = new byte[1024];
- int count=0;
- while((count = bis.read(buffer,0,1024)) != -1)
- {
- fis.write(buffer, 0, count);
- }
- fis.close();
- bis.close();
- }
- }
(这和一般的网络请求有什么不同吗?)
附运行截图:
当然插件的话要考虑一下是否有网络限制等因素(
本帖最后由 Brave_boy 于 2021-10-25 22:23 编辑
微软给的 QQ音乐 网易云 酷狗 腾讯视频 包括我写的MP3播放器 都无法播放 且占用空间为0
flush清空缓存 也加了
RarityEG 发表于 2021-10-25 21:24
获取的音频播放为单词 Home,有问题吗(?
建议检查是否播放器有问题(文件长度仅 1s ...
微软给的 QQ音乐 网易云 酷狗 腾讯视频 包括我写的MP3播放器 都无法播放 且占用空间为0
flush清空缓存 也加了