天天动画片 > 八卦谈 > 跑步背景音乐python开源代码

跑步背景音乐python开源代码

八卦谈 佚名 2023-12-19 18:35:36

from pydub import AudioSegment


# Load your sounds

warmup = AudioSegment.from_mp3("warmup20.mp3")  # load warmup track

workout = AudioSegment.from_mp3("workout.mp3")  # load workout track

moderate = AudioSegment.from_mp3("moderate.mp3")  # load moderate track

cooldown = AudioSegment.from_mp3("cooldown15.mp3")  # load cooldown track

countdown = AudioSegment.from_mp3("countdown.mp3")  # load countdown sound


# Trim the workout and moderate tracks to the desired lengths

workout = workout[:5*60*1000]  # trim to 5 minutes

moderate = moderate[:2*60*1000]  # trim to 2 minutes


# Add the "countdown" sound at the end of each workout

workout = workout.overlay(countdown, position=workout.duration_seconds*1000 - countdown.duration_seconds*1000)


# Trim warmup and cooldown tracks to desired lengths

warmup = warmup[:20*60*1000]

cooldown = cooldown[:15*60*1000]


# Overlay "countdown" sound at the end of warmup

warmup = warmup.overlay(countdown, position=warmup.duration_seconds*1000 - countdown.duration_seconds*1000)


# Generate full workout track

workout_full = AudioSegment.empty()

for i in range(5):

    workout_with_countdown = workout.overlay(countdown, position=workout.duration_seconds*1000 - countdown.duration_seconds*1000)

    moderate_with_countdown = moderate.overlay(countdown, position=moderate.duration_seconds*1000 - countdown.duration_seconds*1000)

    workout_full += workout_with_countdown + moderate_with_countdown


# Combine all tracks

full_track = warmup + workout_full + cooldown


# Save combined track

full_track.export("full_workout_track.mp3", format="mp3")


print("Done.")


需要安装ffmpeg

用https://audiotrimmer.com

调整背景音乐bpm

其他直接改参数即可

本文标题:跑步背景音乐python开源代码 - 八卦谈
本文地址:www.ttdhp.com/article/43355.html

天天动画片声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
扫码关注我们