1

So I am making a game and the music file I want to play in background isn't opening. The error is below:

Traceback (most recent call last):
  File "C:/Users/LENOVO/Desktop/Everything Here!!/sound.py", line 16, in <module>
    hitSound = pygame.mixer.Sound('Game//Hit.wav')
pygame.error: Unable to open file 'Game//Hit.wav'

I suppose the error is probably the frequency of these audio files. But I really don't know how to fix that, and I tried using audacity to change the frequency but the music literally died and nothing was to be heard. So, please tell me a way to fix this without making the sound go away. Here is the code for sound functions:


clock = pygame.time.Clock()

bulletSound = pygame.mixer.Sound('Game//Bullet.wav')
hitSound = pygame.mixer.Sound('Game//Hit.wav')

music = pygame.mixer.music.load('Game//BackgroundMusic.wav')
pygame.mixer.music.play(-1)


  • You should always post your code. In fact, a question without code is more likely to be closed. But please create a [mcve] and don't dump the code for the entire project here. – ForceBru Jan 31 '21 at 16:18
  • @ForceBru thanks for letting me know, I have now uploaded the code too please help me if you can – Bruce Banner Jan 31 '21 at 16:23
  • 1
    So, it correctly executes `bulletSound = pygame.mixer.Sound('Game//Bullet.wav')`, but errors out on the next line, `hitSound = pygame.mixer.Sound('Game//Hit.wav')`... There must be something wrong with this particular file then. Is this file actually there? Can it be played in some audio player, or do audio players complain about it too? – ForceBru Jan 31 '21 at 16:28
  • @ForceBru Well the file is working fine as I have tested it in 3 different audio players and it plays fine then. And yes it is there as the images I have uploaded for the game are also in that folder and are working fine. – Bruce Banner Jan 31 '21 at 16:32
  • I sometimes catch the same error with a corrupted file. All of the file readers detect nothing, but `pygame` doesn't work. So I currently have no other solution but putting the audio file into [Audacity](https://audacity.fr) or an editor like that, then export the file completely reviewed and corrected by the editor. – D_00 Feb 01 '21 at 12:53
  • Or you can export the file into another format with [dBpoweramp](https://www.dbpoweramp.com), or an [online audio converter](https://audio.online-convert.com), which will do the same correcting job to the file. – D_00 Feb 01 '21 at 12:56
  • @D-00 Okay so I did tried to use audacity to convert the file to lower bits by changing its frequency but it did not work because the audio file lost it's music after that. So, can you please elaborate how do I correct these files? – Bruce Banner Feb 02 '21 at 15:32
  • Idk really what's going on with `pygame`, so that's what I've done. I thought while downloading, or another file transfert, the file was corrupted. So I got this semi-solution which avoid partly the problem by using other applications which can restructure the file. But if you don't want to lose quality, you can simply convert your file, for example in `.ogg`, then convert it in `.wav`. – D_00 Feb 04 '21 at 16:19

0 Answers0