Sound abbreviated in PyGame

I use Ubuntu 10.4 and learn PyGame following the instructions "Drop the chimpanzee and win $$$".

I made two .wav files, but when I try to play them, I get a strange noise, like a knock, very short.

I am not getting an error message. Why is this not working as expected?

>>> import pygame
>>> pygame.init()
(6, 0)
>>> def load_sound(name):
    class NoneSound(object):
        def play(self): pass
    if not pygame.mixer:
        return NoneSound()
    fullname = os.path.join('data', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.error, message:
        print 'Cannot load sound:', name
        raise SystemExit, message
    return sound

>>> whiff_sound = load_sound('whiff.wav')
>>> whiff_sound.play()
<Channel object at 0xb772f1c0>
>>> 
+3
source share
3 answers

I had the same problem with sound, I opened my sound in WavePad Sound Editor and re-saved the file as .wav and set the sampling frequency to 22050 Hz, and this solved my problem.

+2
source

, . , , :

pygame.mixer.init( = 22050, size = -16, channels = 2, buffer = 4096): return None

= 22050, , , ( ).

pygame.mixer.Sound :

.

, ...

, , ​​ , .

, !

+3

So far I have not been able to adjust the frequency by setting size = 8 and buffer = 2048 when I called mixer.init () worked for me.

+2
source

Source: https://habr.com/ru/post/1778004/


All Articles