MEL频谱图和MFCC
#编程 #python #audio #mfcc

算法流

Algorithm flow

  • 阅读220Hz音频数据
import audioflux as af

audio_path = af.utils.sample_path('220')
audio_arr, sr = af.read(audio_path)
  • DB的提取光谱图
low_fre = 0
spec_arr, fre_band_arr = af.mel_spectrogram(audio_arr, samplate=sr, low_fre=low_fre)
spec_dB_arr = af.utils.power_to_db(spec_arr)
  • 显示MEL频谱图
import matplotlib.pyplot as plt
from audioflux.display import fill_spec
import numpy as np

# calculate x/y-coords
audio_len = audio_arr.shape[0]
x_coords = np.linspace(0, audio_len/sr, spec_arr.shape[1] + 1)
y_coords = np.insert(fre_band_arr, 0, low_fre)

fig, ax = plt.subplots()
img = fill_spec(spec_dB_arr, axes=ax,
                x_coords=x_coords,
                y_coords=y_coords,
                x_axis='time', y_axis='log',
                title='Mel Spectrogram')
fig.colorbar(img, ax=ax, format="%+2.0f dB")

mel spectrogram

  • 提取MFCC数据
cc_arr, _ = af.mfcc(audio_arr, samplate=sr)
  • 显示MFCC图
# calculate x-coords
audio_len = audio_arr.shape[0]
x_coords = np.linspace(0, audio_len/sr, cc_arr.shape[1] + 1)

fig, ax = plt.subplots()
img = fill_spec(cc_arr, axes=ax,
                x_coords=x_coords, x_axis='time',
                title='MFCC')
fig.colorbar(img, ax=ax)

mfcc