LoginSignup
1
0

More than 1 year has passed since last update.

全ての曲を1分にする2

Last updated at Posted at 2021-12-12

これの続き。
長い曲聴くのだるいと思ったから作った。

1分にする

曲の間を適当に削って1分にする


path = "motoneta.mp3"

import numpy as np
import librosa
import pydub
from pydub import AudioSegment

y, sr = librosa.load(path)
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

# 曲の長さ(ミリ秒
time = int(librosa.get_duration(y=y, sr=sr) * 1000)
# BPMから1ビートの長さをとる(ミリ秒
beat_time = int( 60 / tempo * 1000)

base_sound = AudioSegment.from_file(path, format="mp3")
oneminit_sound = base_sound[0:0]
start_time = 0

# 1分にする
while(True):

    import random
    # 乱数で適当に切り出す箇所の終了位置決める(ここの乱数がいじりどころ
    end_time = start_time + (random.randint(1, 4) * beat_time)

    # 切り出してくっつける
    cut = base_sound[start_time : end_time]
    oneminit_sound = oneminit_sound + cut

    # 1分すぎたら終わり
    if 60000 < len(oneminit_sound):
        break

    # 乱数で適当に切り出す箇所の開始位置決める(ここの乱数がいじりどころ
    start_time = end_time + (random.randint(10, 16) * beat_time)

    # 曲一周したら頭に戻る
    if time < start_time:
        start_time = start_time - int(time)

oneminit_sound[:60000].export("oneminit.mp3", format="mp3")



おしまい

聞いてみた

49秒の曲が1分で6回聞けた、
長さが1/5になったくらいの計算になる。

原曲

感想

忙しい現代人に

今後の展望

今は行儀よく開始から終了の方向で連結してるけど、ランダムに戻ったり逆再生音源差し込んだりしたい

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0