Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

Python 3.9 Pygame mixer frequency change not working

I am using pygame (version = 2.0.1) in python==3.9.1 in windows OS laptop. I use the pygame.mixer module to play my mp3 file. My code:

from time import sleep
from pygame import mixer

audio_length = 5.184

mixer.init(frequency=26500)
# mixer.init(frequency=44100)
mixer.music.load("Test.mp3")

mixer.music.play()
sleep(audio_length)
mixer.music.stop()

mixer.quit()

The above code works without errors.. BUT the audio is played at the same default frequency no matter what value I set in mixer.init().

This seems to be quite strange because the above code works perfectly fine (with frequency change) in python 3.7 and pygame 1.9.6

I realised this only after i thought about upgrading my python version.

Is this a bug which I have to report? In that case how do I proceed so?

Or... is it just that I'm not following the new way in python 3.9?

In case, the file I used for testing is required, you can download from https://drive.google.com/file/d/1vd7aO5ahFBHfoT97_0RSBU4reNAWseB6/view?usp=sharing


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Mixer init expects to also get the size and the channels, so you will have to do it like this:

mixer.init(frequency=26500, size=-16, channels=2)

For more info, see pygame docs: https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...