Algorithm flow
![Algorithm flow](https://res.cloudinary.com/practicaldev/image/fetch/s--E164iWYi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/77itb11zc9r0e2p1pepb.png)
import audioflux as af
audio_path = af.utils.sample_path('220')
audio_arr, sr = af.read(audio_path)
- Extract spectrogram of 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)
- Show mel spectrogram plot
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](https://res.cloudinary.com/practicaldev/image/fetch/s--K5I62Ky5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/idmrjz96bmaazgbi3l6y.png)
cc_arr, _ = af.mfcc(audio_arr, samplate=sr)
# 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](https://res.cloudinary.com/practicaldev/image/fetch/s--EdJa6rKV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80lh0hj6z6v5oneb02jh.png)
Top comments (0)