转换为 mfcc 时如何循环访问音频文件



我是初学者,我正在将音频文件转换为 mfccs,我已经为一个文件完成了它,但不知道如何遍历所有数据集。我在训练文件夹中有多个文件夹,其中一个是 001(0(,从中转换了一个 wav 文件。我想转换训练文件夹中存在的所有文件夹的 wav 文件

import os
import numpy as np
import matplotlib.pyplot as plt
from glob import glob
import scipy.io.wavfile as wav
from python_speech_features import mfcc, logfbank
# Read the input audio file
(rate,sig) = wav.read('Downloads/DataVoices/Training/001(0)/001000.wav')

# Take the first 10,000 samples for analysis
sig = sig[:10000]
features_mfcc = mfcc(sig,rate)
# Print the parameters for MFCC
print('nMFCC:nNumber of windows =', features_mfcc.shape[0])
print('Length of each feature =', features_mfcc.shape[1])
# Plot the features
features_mfcc = features_mfcc.T
plt.matshow(features_mfcc)
plt.title('MFCC')
# Extract the Filter Bank features
features_fb = logfbank(sig, rate)
# Print the parameters for Filter Bank 
print('nFilter bank:nNumber of windows =', features_fb.shape[0])
print('Length of each feature =', features_fb.shape[1])
# Plot the features
features_fb = features_fb.T
plt.matshow(features_fb)
plt.title('Filter bank')
plt.show()

您可以将 glob 与通配符递归使用来查找所有 wav 文件。

for f in glob.glob(r'Downloads/DataVoices/Training/**/*.wav', recursive=True):
     (rate,sig) = wav.read(f)
     # Rest of your code

相关内容

  • 没有找到相关文章

最新更新