使用 PyGame 加载 MP3 并淡出 [英] Using PyGame to Load MP3 and Fade Out

查看:54
本文介绍了使用 PyGame 加载 MP3 并淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我们的 GoPigo 中加入声音,并且我正在使用 Python.我安装了 PyGame 并尝试使用 fadeout 但它似乎不起作用.它不会产生错误,但从我运行代码时听到的情况来看,它不会淡出.任何想法

I am trying to incorporate sounds in our GoPigo and I am using Python. I installed PyGame and was trying to use fadeout but it seems not working. It doesn't generate an error but from what I am hearing when I run the code is that doesn't fade out. Any ideas

def sound_bytes2():
    import pygame
    import time

    audio1 = "audio1.mp3"
    audio2 = "audio2.mp3"

    pygame.mixer.init()


    pygame.mixer.music.load(audio1)
    pygame.mixer.music.play()
    time.sleep(12.5)
    pygame.mixer.music.fadeout(10) 
    #pygame.mixer.music.stop()

    pygame.mixer.music.load(audio2)
    pygame.mixer.music.play(start=6.5)
    pygame.mixer.music.get_pos()
    time.sleep(11.3)
    pygame.mixer.music.stop()

推荐答案

pygame.mixer.music.fadeout() 是毫秒.10 秒是 10000 毫秒:

The unit of the time parameter to pygame.mixer.music.fadeout() is milliseconds. 10 seconds are 10000 milliseconds:

pygame.mixer.music.load(audio1)
pygame.mixer.music.play()

# play for 12.5 seconds
pygame.time.wait(12500)

# fade out for 10 seconds
pygame.mixer.music.fadeout(10000) 
pygame.time.wait(10000)

这篇关于使用 PyGame 加载 MP3 并淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆