gpt4 book ai didi

python - 从 URL 获取音频并播放

转载 作者:行者123 更新时间:2023-12-01 08:59:25 28 4
gpt4 key购买 nike

有一个指向 mp3 的链接需要从URL流式传输的文件喜欢 http://example.com/music_radio.mp3并在电脑上玩。网上虽然有流音频的例子,但主要都是针对Python2 ,以及 Python3不再有这样的库了,我尝试这样做:

import vlc
p = vlc.MediaPlayer ("http://example.com/music_radio.mp3")
p.play ()

但它不断显示错误:

Traceback (most recent call last): File "PythonProjects / URL / main.py", line 2, in import vlc File "PythonProjects / URL / venv / lib / python3.6 / site-packages / vlc / init.py", line 3, in public import ModuleNotFoundError: No module named 'public'

问题是public模块未安装。如何解决这个问题或者如何通过引用接收和播放音频?

UPD:该链接建议使用非工作代码,或使用 Python2 而非 Python3 的代码

UPD2:使用 python-vlc 时,出现这个错误:

Traceback (most recent call last): File "PythonProjects/URL/main.py", line 4, in import vlc File "PythonProjects/URL/venv/lib/python3.6/site-packages/vlc.py", line 203, in dll, plugin_path = find_lib() File "PythonProjects/URL/venv/lib/python3.6/site-packages/vlc.py", line 194, in find_lib ctypes.CDLL('libvlccore.dylib') File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/init.py", line 348, in init self._handle = _dlopen(self._name, mode) OSError: dlopen(libvlccore.dylib, 6): image not found

最佳答案

如果这可以帮助

from IPython.display import Audio
Audio(url="http://www.nch.com.au/acm/8k16bitpcm.wav")

关于python - 从 URL 获取音频并播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52575782/

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