问题描述
我正在尝试使用 pygame 播放声音文件 (.wav),但是当我启动它时,我听不到任何声音.
这是代码:
I'm trying to play sound files (.wav) with pygame but when I start it I never hear anything.
This is the code:
import pygame
pygame.init()
pygame.mixer.init()
sounda= pygame.mixer.Sound("desert_rustle.wav")
sounda.play()
我也尝试过使用通道,但结果是一样的
I also tried using channels but the result is the same
推荐答案
你的代码在我的机器上运行 desert_rustle.wav
非常好(Mac OSX 10.5、Python 2.6.4、pygame 1.9.1).您使用的是什么操作系统、Python 和 pygame 版本?您能否通过其他方式听到 .wav
OK(例如,Mac 终端上的 open
或 Windows 控制台上的 start
后跟文件名/路径).wav
文件)来保证文件没有损坏?在无法重现问题且没有所有这些关键细节的情况下,很难调试您的特定问题(不是使用您提供的代码).
Your code plays desert_rustle.wav
quite fine on my machine (Mac OSX 10.5, Python 2.6.4, pygame 1.9.1). What OS and Python and pygame releases are you using? Can you hear the .wav
OK by other means (e.g. open
on a Mac's terminal or start
on a Windows console followed by the filename/path to the .wav
file) to guarante the file is not damaged? It's hard to debug your specific problem (which is not with the code you give) without being able to reproduce it and without having all of these crucial details.
这篇关于Pygame,声音不播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!