简体   繁体   中英

Pygame mixer clicking sound

Okay here's my code:

import pygame

pygame.init() 
pygame.mixer.init()

track1 = pygame.mixer.Sound("boink.ogg")
track1.play()

So I am using a mac and I used homebrew to download the pygame 64 bit version. Everything works well, but when I try to make sounds using the mixer, all that I hear is a clicking sound. Has anyone experienced this in the past that may be able to help?

Also I have tried this with many different ogg files, so it is not something wrong with the sound file.

Can you try this?

import pygame
import time

pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
song = pygame.mixer.Sound('boink.ogg')
song.play()
time.sleep(song.get_length())

Not to sound crude, but have you tried playing a file without using any kind of object? , just play simple sound file and see if it works? I usually start that way.

Here is what I tried as basics (and it works). Do mind, this is on windows as I do not own a MAC, but it will provide insight into if at all file is playing.

Also, try playing different format files (wav , mp3 etc).

import pygame

pygame.mixer.init()
pygame.mixer.music.load('boink.ogg')
pygame.mixer.music.play(0)

I had the same click when playing an mp3 with the pygame.mixer.Sound and .play code.

This worked for me:

pygame.mixer.pre_init()

#then instantiate and start your controller

pygame.mixer.init()

#then in your button click or wherever
pygame.mixer.music.load('mysound.mp3')
pygame.mixer.music.play()

A few things you can try:

  • Make sure that the path to your sound file is correct.
  • Turns out Pygame's pygame.mixer.Sound() only accepts Mono WAV sound files.

for my second point, you can go here to convert your ogg file to mono wav files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM