Raspberry pi with pygame.mixer audio produces only static

爷,独闯天下 提交于 2021-02-16 21:14:05

问题


I'm quite new with raspberry pi and am very new but I am trying to play an audio file through a python file on a pi B. I played the audio from the command line using omxplayer and it worked fine but when i run the following code it plays only static.

from pygame import mixer
mixer.init()
wow = mixer.Sound('Wow.mp3')
wow.play()
time.sleep(5)

I tried using mixer.load('Wow.mp3') and other variations but still only get static. I tried putting things in the init like mixer.init(4800, -16, 1, 1024) and using pre_init but to no avail. I also tried adding disable_audio_dither=1 to config.txt. Any and all help would be greatly appreciated thank you very much.


回答1:


Sometimes if sound is supposed to be playing but isn't, and the speakers are turned all the way up, it will play static instead. This is probably a computer problem, not a pygame problem. Check whether audio plays in other locations. If it does not, it is definitely a computer problem.

If using Linux (you probably are, Raspbian is a variant of Debian which is Linux), and you have identified that it is a computer problem, try initializing ALSA by typing alsactl init as root in the Linux Terminal. If this does not work and the above is true, then you are having some audio problems that will take a bit of research to fix.

If audio does play in other locations, then it is probably a file format issue. It's possible that the bitrate is different, the format is wrong, etc. Also, here is a quote pulled directly from Pygame documentation:

Be aware that MP3 support is limited. On some systems an unsupported format can crash the program, e.g. Debian Linux. Consider using OGG instead.

https://www.pygame.org/docs/ref/music.html

Other than this, there isn't much we can do to help you. A problem like this that isn't fixed by the above is usually a problem specific to very few computer setups. You will probably have to do some personal research.

If you need any more help, please notify me in the comments.



来源:https://stackoverflow.com/questions/42282700/raspberry-pi-with-pygame-mixer-audio-produces-only-static

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!