Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pygame audio playback speed

Tags:

python

pygame

quick question.

I'm running pygame under linux just to play some audio files. I've got some .wav files and I'm having problems playing them back at the right speed.

import pygame.mixer, sys, time

#plays too fast
pygame.mixer.init(44100)
pygame.mixer.music.load(sys.argv[1])
pygame.mixer.music.play()
time.sleep(5)
pygame.mixer.quit()

#plays too slow
pygame.mixer.init(22100)
pygame.mixer.music.load(sys.argv[1])
pygame.mixer.music.play()
time.sleep(5)
pygame.mixer.quit()

I've ggogle code searched some stuff but everybody seems to be fine calling the init function with its default parameters. Can others try running this script and seeing if they get the same behavior or not? Does anybody know how to speed it up? Or adjust the speed for each file?

Thanks.

like image 347
Chris H Avatar asked Jan 29 '10 01:01

Chris H


People also ask

Does Pygame support WAV files?

Pygame can load WAV, MP3, or OGG files.

Does pygame work with MP3?

PyGame can handle . mp3 as well, but it is somewhat glitchy, and will work sometimes and other times it wont. For the safest bet, go with . wav.


2 Answers

Open your audio file in a free audio tool like Audacity. It will tell you the sampling rate of your media. It will also allow you to convert to a different sampling rate so all your sounds can be the same.

like image 127
Pace Avatar answered Sep 22 '22 14:09

Pace


I figured it out... There is a wave module http://docs.python.org/library/wave.html and it can read the sample rate for wav files.

like image 25
Chris H Avatar answered Sep 19 '22 14:09

Chris H