如何使用 VSCode 在 Jupyter 笔记本中播放音频?
在 VSCode 中使用 jupyter 笔记本,我尝试从此 文档:
import numpy as np
from IPython.display import Audio
framerate = 44100
t = np.linspace(0,5,framerate*5)
data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t)
Audio(data, rate=framerate)
但是,我只得到这个
如果我按播放按钮,则什么也不会发生...
Using a jupyter notebook in VSCode, I'm trying to run the following code from this documentation:
import numpy as np
from IPython.display import Audio
framerate = 44100
t = np.linspace(0,5,framerate*5)
data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t)
Audio(data, rate=framerate)
However, I only get this
If I press play button, then nothing happens...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
截至今天,VSCode Jupyter 扩展似乎不支持音频。您可以在 此处在他们的 Github 上跟踪该问题。
一种解决方案可以是合并此拉取请求并重建 VSCode,这是不建议。
对于此类用例,首选的替代解决方案是使用
jupyter lab
而不是 VSCode。As of today, it seems VSCode Jupyter extension does not support audio. You can track the issue here on their Github.
One solution can be merging this pull request and rebuilding VSCode, which is not suggested.
The preferred alternate solution is using
jupyter lab
instead of VSCode for such use cases.从版本 1.7 开始,似乎他们已经修复了该问题 。
As of version 1.7, it seems they’ve fixed it.
几个月前我就看到了这个工作。
但目前我的系统是 Ubuntu 23.04,带有 miniconda,包括 python 3.11 和 Visual Studio Code via snap,所以是最新版本。
我可以按播放按钮,但听不到任何声音。
使用 miniconda 中的 Jupyter Lab,使用相同的 conda 内核,声音工作正常。
因此,通过 IPython 进行的音频在 VSCode 中似乎被破坏了,而几个月前它还可以工作。
[编辑 2023/05/20] 我卸载了 VSCode 的 snap 版本。并直接安装:
之后一切正常。所以我的问题是特定的。
I have seen this working a few months ago.
But currently my system is Ubuntu 23.04 with miniconda including python 3.11 and Visual Studio Code via snap, so latest version.
I can press the play button, but can not hear any sound.
With Jupyter Lab in miniconda, with the same conda kernel, sound is working fine.
So it seems that Audio via IPython is broken in VSCode while it worked a few months ago.
[EDIT 2023/05/20] I uninstalled the snap version of VSCode. And installed it directly:
and after that it all works fine. So my issue was snap specific.
截至 2024 年 2 月 14 日,此功能有效
但有 一个看起来很难解决的问题。 VScode 忽略
autoplay=True
。但如果你点击“播放”,它就可以正常工作。
我只需要解决这个问题,
我需要自动播放,因为我有错误和笔记本结尾的声音,并且必须自动播放这些声音来告诉我声音的内容(以及其他声音)。
As of 2024-02-14 this works
But there is an issue that seems difficult to be solved. VScode ignores the
autoplay=True
.But if you click Play it works fine.
I just had to workaround that with
I needed the Autoplay because I have sounds for errors and for end-of-notebook-reached and those must be played automatically to tell me stuff with sounds (among other sounds).