快速提问。
我在linux下运行pygame只是为了播放一些音频文件。
我有一些 .wav 文件,但在以正确的速度播放它们时遇到问题。
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()
我已经用 ggogle 代码搜索了一些东西,但每个人似乎都可以使用默认参数调用 init 函数。其他人可以尝试运行这个脚本并看看他们是否得到相同的行为吗?有人知道如何加快速度吗?或者调整每个文件的速度?
Thanks.
我的一些 mp3 音轨播放速度变慢。我将混频器频率更新为基于 mp3 采样率,使用mutagen https://mutagen.readthedocs.io/en/latest/api/mp3.html像这样:
import pygame, mutagen.mp3
song_file = "your_music.mp3"
mp3 = mutagen.mp3.MP3(song_file)
pygame.mixer.init(frequency=mp3.info.sample_rate)
pygame.mixer.music.load(song_file)
pygame.mixer.music.play()
它解决了问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)