gpt4 book ai didi

python - 如何使用 python 捕获 mp3 流

转载 作者:太空狗 更新时间:2023-10-29 17:58:24 25 4
gpt4 key购买 nike

捕获来自 http 的 mp3 流并使用 python 将其保存到磁盘的最佳方法是什么?

到目前为止我已经尝试过

target = open(target_path, "w")
conn = urllib.urlopen(stream_url)
while True:
target.write(conn.read(buf_size))

这给了我数据,但它在 mp3 播放器中出现乱码或无法播放。

最佳答案

如果您使用的是 Windows,您可能会不小心进行 CRLF 转换,从而损坏二进制数据。尝试以二进制模式打开 target:

target = open(target_path, "wb")

关于python - 如何使用 python 捕获 mp3 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/187552/

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