带有 pygame.mixer 音频的 Raspberry pi 仅产生静态 [英] Raspberry pi with pygame.mixer audio produces only static

查看:25
本文介绍了带有 pygame.mixer 音频的 Raspberry pi 仅产生静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 raspberry pi 很陌生,而且很新,但我试图通过 pi B 上的 python 文件播放音频文件.我使用 omxplayer 从命令行播放音频,它工作正常,但是当我运行以下代码,它只播放静态.

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)

我尝试使用 mix.load('Wow.mp3') 和其他变体,但仍然只是静态的.我尝试将东西放入 init 中,例如 mix.init(4800, -16, 1, 1024) 并使用 pre_init 但无济于事.我还尝试将 disable_audio_dither=1 添加到 config.txt.非常感谢您提供任何帮助.

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.

推荐答案

有时如果声音应该播放但没有播放,并且扬声器一直向上转动,它会改为播放静态.这可能是计算机问题,而不是 pygame 问题.检查音频是否在其他位置播放.如果没有,那肯定是电脑问题.

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.

如果使用 Linux(您可能是,Raspbian 是 Debian 的一个变体,也就是 Linux),并且您已经确定这是一个计算机问题,请尝试通过键入 alsactl init 来初始化 ALSA在 Linux 终端中以 root 身份.如果这不起作用并且上述情况属实,那么您遇到了一些音频问题,需要进行一些研究才能解决.

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.

如果音频确实在其他位置播放,则可能是文件格式问题.可能是比特率不同,格式错误等.此外,这里是直接从 Pygame 文档中提取的引用:

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:

请注意 MP3 支持是有限的.在某些系统上,不受支持的格式可能会导致程序崩溃,例如Debian Linux.考虑改用 OGG.

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.

这篇关于带有 pygame.mixer 音频的 Raspberry pi 仅产生静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆