librosa.feature.melspectrogram() 梅尔频谱图 示例
import librosa
y, sr = librosa.load(
librosa.ex('nutcracker'), # 音频路径( librosa.ex('nutcracker') 可换成:1.wav )
sr = 18000, # 设置输出采样率,默认是22050
duration = 1 # 截取时长为1秒
)
print(y.shape) # 音频时间序列
(18000,)
spec = librosa.feature.melspectrogram(
y=y, #
sr=18000, # 采样率
n_mels=90,
n_fft=900, # FFT窗口的长度
hop_length=200 # 步长
)
print(spec.shape)
# spec.shape[1] = y.shape[0] // hop_length + 1
# spec.shape[0] = n_mels
(90, 91)