Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python MusicalBeep导致错误_Python - Fatal编程技术网

Python MusicalBeep导致错误

Python MusicalBeep导致错误,python,Python,我开始使用该模块尝试用Python播放音乐,但是,每当我尝试让播放器播放噪音时,我都会得到一个巨大的错误。我的代码现在看起来像这样: import musicalbeeps as music global TempPlayer def PlayNote(Note, Octive, Accidental, Duration, Volume): #Accidental is either # (sharp) or b (flat) or '' (none) global TempPlay

我开始使用该模块尝试用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
ALSA lib confmisc.c:767:(解析卡)找不到卡“0”
ALSA lib conf.c:4528:(_snd_config_evaluate)函数snd_func_card_驱动程序返回错误:没有这样的文件或目录
ALSA lib confmisc.c:392:(snd_func_concat)计算字符串时出错
ALSA lib conf.c:4528:(_snd_config_evaluate)函数snd_func_concat返回错误:没有这样的文件或目录
ALSA lib confmisc.c:1246:(snd_func_REFERE)计算名称时出错
ALSA lib conf.c:4528:(_snd_config_evaluate)函数snd_func_refere返回错误:没有这样的文件或目录
ALSA lib conf.c:5007:(snd_config_expand)评估错误:没有这样的文件或目录
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate)未知pcm默认值
回溯(最近一次呼叫最后一次):
文件“main.py”,第13行,在
纸条(“B”,4,“#”,5,1)
PlayNote中第9行的文件“main.py”
templayer.play_note(“{}{}}”)。格式(note,Octive,contractive),持续时间
文件“/opt/virtualenvs/python3/lib/python3.8/site packages/musicalbeeps/beepsplayer.py”,第138行,播放中注释
自写入流(持续时间)
文件“/opt/virtualenvs/python3/lib/python3.8/site packages/musicalbeeps/beepsplayer.py”,第118行,在写入流中
self.\u play\u obj=sa.play\u缓冲区(音频,1,2,self.rate)
文件“/opt/virtualenvs/python3/lib/python3.8/site packages/simpleudio/shinny.py”,第60行,在播放缓冲区中
播放id=\u sa.\u播放缓冲区(音频数据、频道数、每个样本的字节数、,
_simpleaudio.SimpleaudioError:打开PCM设备时出错。--代码:-2--MSG:没有这样的文件或目录
顺便说一句,我正在使用它,我已经将musicbeeps模块下载到文件中


请帮助我,我只是想做一个简单的项目谢谢你提供了指向已安装软件包的链接-这使找到解决方案变得更容易。MusicalBeeps取决于simpleaudio,它需要(至少在linux上-当你发布ALSA错误时,我假设这是linux)要安装的libasound2 dev开发库。请参阅repl上的

Code。它运行在离您很远的服务器上。即使该服务器连接了音频硬件,您也听不到。@jasonharper,所以如果我在终端或我计算机上的其他应用程序中运行此代码,它也会工作?可能,我不会了解您尝试使用的此模块的系统要求,它可能需要特定的平台。