python - Pygame错误: not able to open . wav文件

标签 python pygame

我的 Pygame 程序有问题。我需要帮助。 wav 文件与 python 文件位于同一目录中。 我在终端-Python3 中运行它:

import pygame.mixer
sounds = pygame.mixer
sounds.init()

def wait_finish(channel):
    while channel.get_busy():
        pass

asked = 0
true = 0
false = 0

choice = str(input("Push 1 for true, 2 for false, 0 to end"))
while choice != '0':
      if choice == '1':
             asked = asked + 1
             true = true + 1
             s = sounds.Sound("correct.wav")
             wait_finish(s.play())
      if choice == '2':
             asked = asked + 1
             false = false + 1
             s = sounds.Sound("wrong.wav")
             wait_finish(s.play())
      choice = str(input("Push 1 for true, 2 for false, 0 to end"))

print ("you asked" +str(asked) + "questions")
print ("there were" +str(false) + "wrong answers")
print ("and" + str(true) + "correct answers")

它抛出- pygame.error:

Unable to open file 'correct.wav'

最佳答案

我有同样的问题,无法让这段代码工作:

correctSound = pygame.mixer.Sound('jingle3.wav')

我遇到了 pygame 错误:

Unable to open file 'jingle3.wav'

通过将“jingle3.wav”加载到 Audicity 并将其从 32 位 PCM 更改为 16 位 PCM .wav 文件,问题得以解决。之后 pygame.mixer.Sound 完美运行。

我在这个论坛上得到了这个提示,它奏效了!

关于python - Pygame错误: not able to open . wav文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32862110/

相关文章:

python - 在 matplotlib 中创建发散堆积条形图

python - 如何阅读小部件的样式表?

python - 是否有公钥流密码加密?

python-3.x - 使用文件对话框加载音频文件并使用 pygame 播放

python - Pygame中的声音问题

Python 游戏 "an integer is required"

python - 如何从Python中的字典列表中合并字典?

python - 将 Django 应用程序部署到 Heroku 会导致错误worker failed to boot

Python - Pygame - 获取特定声音是否正在播放

python - Pygame:按住键时玩家不会移动