首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python MusicalBeeps导致错误

Python MusicalBeeps导致错误
EN

Stack Overflow用户
提问于 2020-05-30 06:17:10
回答 1查看 362关注 0票数 0

我开始使用模块MusicalBeeps来尝试在Python语言中播放音乐,然而,每当我尝试让播放器播放噪声时,我都会收到一个巨大的错误。我的代码现在看起来像这样:

代码语言:javascript
运行
复制
import musicalbeeps as music

global TempPlayer

def PlayNote(Note, Octive, Accidental, Duration, Volume):
  #Accidental is either # (sharp) or b (flat) or '' (none)
  global TempPlayer
  TempPlayer = music.Player(volume = float(Volume), mute_output = False)
  TempPlayer.play_note("{}{}{}".format(Note, Octive, Accidental), Duration)
  TempPlayer = None

print("Running...")
PlayNote("B", 4, "#", 5, 1)
print("Done!")

这是他们在网站上展示的例子,但是每当我尝试运行它时,我都会得到这个奇怪的错误:

代码语言:javascript
运行
复制
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
Traceback (most recent call last):
  File "main.py", line 13, in <module>
    PlayNote("B", 4, "#", 5, 1)
  File "main.py", line 9, in PlayNote
    TempPlayer.play_note("{}{}{}".format(Note, Octive, Accidental), Duration)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/musicalbeeps/beepsplayer.py", line 138, in play_note
    self.__write_stream(duration)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/musicalbeeps/beepsplayer.py", line 118, in __write_stream
    self._play_obj = sa.play_buffer(audio, 1, 2, self.rate)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/simpleaudio/shiny.py", line 60, in play_buffer
    play_id = _sa._play_buffer(audio_data, num_channels, bytes_per_sample,
_simpleaudio.SimpleaudioError: Error opening PCM device. -- CODE: -2 -- MSG: No such file or directory

顺便说一句,我正在使用repl.it来实现这一点,并且我已经将musicbeeps模块下载到了文件中。

请帮帮忙,我只是想做一个简单的项目😀

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-30 06:28:27

感谢您提供的已安装软件包的链接-它使查找解决方案变得更容易。MusicalBeeps依赖于simpleaudio,这需要安装libasound2-dev开发库(至少在linux上是这样的--正如您发布的ALSA错误,我假设这是Linux)。请参阅https://simpleaudio.readthedocs.io/en/latest/installation.html#linux-dependencies

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62095372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档