我正在开发语音识别系统,我从GitHub获得了代码。在这里添加了一些代码:
DATASET_PATH = "F://MS//MS-4//LibriSpeech"
*JSON_PATH = "data_10.json"
SAMPLE_RATE = 22050
TRACK_DURATION = 15
SAMPLES_PER_TRACK = SAMPLE_RATE * TRACK_DURATION*
def save_mfcc (dataset_path, json_path, n_mfcc=13, n_fft=2048, hop_length=512, num_segments=5):
data = {
"mapping": [ ],
"mfcc": [ ],
"labels": [ ]}
num_samples_per_segment = int(SAMPLES_PER_TRACK / num_segments)
expected_num_mfcc_vectors_per_segment = math.ceil(num_samples_per_segment / hop_length)
for i, (dirpath, dirnames, filenames) in enumerate(os.walk(dataset_path)):
if dirpath is not dataset_path:
dirpath_components = os.path.split(dirpath)
semantic_label = dirpath_components[-1]
data["mapping"].append(semantic_label)
print("nProcessing: {}".format(semantic_label))
for f in filenames:
file_path = os.path.join(dirpath, f)
signal, sr = librosa.load(file_path, sr = SAMPLE_RATE)
for s in range(num_segments):
start_sample = num_samples_per_segment * s
finish_sample = start_sample + num_samples_per_segment
mfcc=librosa.feature.mfcc(signal[start_sample:finish_sample],sr=sr,n_fft=n_fft,n_mfcc=n_mfcc,hop_length=hop_length)
mfcc = mfcc.T
if len(mfcc) == expected_num_mfcc_vectors_per_segment:
data["mfcc"].append(mfcc.tolist())
data["labels"].append(i-1)
print("{}, segment:{}".format(file_path, s+1 ))
with open(json_path, "w") as fp:
json.dump(data, fp, indent=4)
if __name__ == "__main__":
save_mfcc(DATASET_PATH, JSON_PATH, num_segments=10)
这就是错误。我想知道如何修复:
警告(来自警告模块(:
文件"C: \Users\Hp\AppData\Local\Programs\Python39\lib\site packages\librosa\core\sspectrum.py";,第222行
警告.warn(
用户警告:n_fft=2048对于长度=0 的输入信号来说太小追溯(最近一次调用(:
文件"C: \Users\Hp\AppData\Local\Programs\Python39\datasetread.py";,第73行,在
save_mfcc(DATASET_PATH,JSON_PATH,num_segments=10(中文件";C: \Users\Hp\AppData\Local\Programs\Python39\datasetread.py";,第55行,在save_mfcc中
mfcc=librosa.feature.mfcc(信号[start_sample:finish_sample],sr=sr,n_fft=n_fft,n_mfcc=n_mfcc,hop_length=hop_length(文件";C: \Users\Hp\AppData\Local\Programs\Python39\lib\site packages\librosa\feature\sspectral.py",第1852行,mfcc
S=功率_to_db(熔化光谱图(y=y,sr=sr,**kwargs((文件";C: \Users\Hp\AppData\Local\Programs\Python39\lib\site packages\librosa\feature\sspectral.py",1996行,在光谱图
S中,n_fft=光谱图(文件";C: \Users\Hp\AppData\Local\Programs\Python39\lib\site packages\librosa\core\sspectrum.py";,第2512行,在_光谱图
stft(文件";C: \Users\Hp\AppData\Local\Programs\Python39\lib\site packages\librosa\core\sspectrum.py";,第228行,stft
y=np.pad(y,int(n_fft//2(,mode=pad_mode(文件"<array_function内部构件>";,第5行,在pad
File";C: \Users\Hp\AppData\Local\Programs\Python39\lib\site packages\numpy\lib\arraypad.py",第814行,在pad
raise ValueError(ValueError:无法使用"常量"或"空"以外的模式扩展空轴0
请确定导致此错误或可能导致更多错误的所有错误。提前谢谢。
在您的代码中,TRACK_DURATION=15(秒(,但我认为在您的数据集中可能有一些持续时间小于15秒的轨迹(文件(。所以试着减少TRACK_DURATION