LoginSignup
3
2

More than 1 year has passed since last update.

Python + librosa で14平米にスーベニア -広川恵一 Remix-から久川凪を救出する

Last updated at Posted at 2022-06-19

Twitterで話題の久川凪をpythonライブラリのlibrosaを使ってプロットしてみました

コード

import numpy as np
import librosa
import librosa.display
from matplotlib import pyplot as plt
from matplotlib import cm
from matplotlib import ticker


file_path = r'./souvenir.wav'
y, sr = librosa.load(file_path, sr=44100)

# スペクトログラムの生成
D = librosa.stft(y, n_fft=2048)  # STFT
S = np.abs(D)
S_db = librosa.amplitude_to_db(S, ref=np.max)  # db変換

# プロット
fig, ax = plt.subplots(dpi=300)
img = librosa.display.specshow(S_db, sr=sr, x_axis='time', y_axis='hz', ax=ax, cmap=cm.gray)

# 177.6秒から182.1秒あたりに画像が埋め込まれている
ax.set_xlim([177, 183])
ax.set_ylim([0, 22050])
ax.set_aspect((183 - 177) / (22050 - 0))  # アスペクト比を1:1に

ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(1))

fig.colorbar(img, format='%+2.0f db')
fig.savefig('./souvenir.png')
fig.show() 

久川凪

souvenir.png

やったぜ。

音源を購入したい方は以下のサイトからどうぞ。

3
2
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
3
2