2

python is playing the sound in slowmotion.bitrate of the fle. Below is the code:

import pygame,time
pygame.mixer.init()
pygame.mixer.music.load('backgroundmusic.mp3')
pygame.mixer.music.play(-1)
time.sleep(20)
pygame.mixer.music.stop()
theAlse
  • 5,577
  • 11
  • 68
  • 110
Dcoder
  • 21
  • 3
  • 2
    What is the bitrate of the mp3? You can set one in [`pygame.mixer.init()`](http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init) – ninMonkey Apr 16 '13 at 18:10
  • 1
    Possible duplicate of [pygame audio playback speed](http://stackoverflow.com/questions/2159365/pygame-audio-playback-speed) – Charles Clayton Feb 18 '17 at 16:28

1 Answers1

1

When you export a sound file to mp3, there is a certain bit rate. This is basically how fast the sound plays. If the bit rate is wrong, the sound plays too fast or too slow. Pygame.mixer is set to play things at the bit rate that will already be default on the program that you save the file on, but if you downloaded the file online this could be difficult. It is best to just set the bitrate to the one of the file using the "size" argument of mixer.init(). However there may be another problem: While pygame.music may support mp3 files, I beleive pygame.mixer is intended for wav files. All this being said, your script doesn't have any issues, but it would be best to save it as a .wav file.

trevorKirkby
  • 1,886
  • 20
  • 47