转换为 mfcc 时如何遍历音频文件

How to iterate through audio files when converting into mfccs

我是初学者,我正在将音频文件转换为 mfccs,我已经完成了一个文件,但不知道如何遍历所有数据集。我在 Training 文件夹中有多个文件夹,其中一个是 001(0),其中一个 wav 文件是 converted.I 想要转换 Training 文件夹中存在的所有文件夹的 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