pygame的不能打开声音文件 [英] Pygame cannot open sound file

查看:1939
本文介绍了pygame的不能打开声音文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import pygame, time
from pygame.locals import *

soundObj = pygame.mixer.Sound('beeps.wav')
soundObj.play()

time.sleep(1) # wait and let the sound play for 1 second
soundObj.stop()

和它抛出这个错误:

Traceback (most recent call last):
  File "C:/Users/Jauhar/Desktop/Python/sounds.py", line 4, in <module>
    soundObj = pygame.mixer.Sound('beeps.wav')
pygame.error: Unable to open file 'beeps.wav'

该beeps.wav文件保存在同一目录蟒蛇文件中的code在

The beeps.wav file is saved in the same directory as the python file the code is in.

我不明白为什么它不会工作!

I can't understand why it won't work!

推荐答案

您不能,除非你初始化或者您的使用或所有Pygame的模块使用pygames'库的。

You cannot use pygames' library's unless you initialize either the modules your using or all of pygame.

    pygame.mixer.pre_init(44100, 16, 2, 4096) #frequency, size, channels, buffersize
    pygame.init() #turn all of pygame on.

做这些,你在做什么的Pygame之前。我推荐它。

do these before you do anything in pygame. I recommend it.

这篇关于pygame的不能打开声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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