我开始使用模块MusicalBeeps来尝试在Python语言中播放音乐,然而,每当我尝试让播放器播放噪声时,我都会收到一个巨大的错误。我的代码现在看起来像这样:
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!")
这是他们在网站上展示的例子,但是每当我尝试运行它时,我都会得到这个奇怪的错误:
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模块下载到了文件中。
请帮帮忙,我只是想做一个简单的项目😀
发布于 2020-05-30 06:28:27
感谢您提供的已安装软件包的链接-它使查找解决方案变得更容易。MusicalBeeps依赖于simpleaudio,这需要安装libasound2-dev开发库(至少在linux上是这样的--正如您发布的ALSA错误,我假设这是Linux)。请参阅https://simpleaudio.readthedocs.io/en/latest/installation.html#linux-dependencies
https://stackoverflow.com/questions/62095372
复制相似问题