Pygame播放mp3文件的速度比正常速度快

问题描述 投票:1回答:1

我使用Python播放简短的mp3音频文件。但是播放速度比其他音乐播放器快。

我的代码:

import pygame
import time
pygame.mixer.init(frequency=22050, size=16, channels=2, buffer=4096)
file=r'test.mp3'
try:
    pygame.mixer_music.load(file)
    pygame.mixer_music.play()
    while pygame.mixer_music.get_busy():
        time.sleep(0.1)
except Exception as err:
    print(err)

请帮助我解决此问题!

python pygame mp3
1个回答
-1
投票
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()
© www.soinside.com 2019 - 2024. All rights reserved.