我在react中通过客户端上传音频,并使用multer将这些文件保存在服务器端的“public/uploads”文件夹中。然后基于这些音频,我想训练一个说话人识别模型。在该training_model.py
python脚本中,我给出了“public/uploads”文件夹的路径,在该文件夹中保存了用于培训模型的音频,但给出了:
PermissionError: [Errno 13] Permission denied
。
该文件夹的所有路径都保存在名为signupVoices.txt
的文本文件中。我尝试使用os.access()
查看权限,结果返回true。尝试更改文件夹的权限,并以管理员身份运行脚本。包含路径的txt文件也已成功读取
培训_model.py:
#import SpeechRecognition as sr
import pickle
import numpy as np
import os
from scipy.io.wavfile import read
from sklearn.mixture import GaussianMixture as GMM
# from sklearn.mixture import GMM
from feature_extraction import extract_features
import warnings
warnings.filterwarnings("ignore")
#path to training data
source = "public/uploads"
print( os.access('public/uploads', os.R_OK))
#path where training speakers will be saved
dest = "speaker_models/"
train_file = "signupVoices.txt"
for files in os.listdir("./public/uploads"):
print (files)
file_paths = open(train_file,'r')
count = 1
# Extracting features for each speaker (5 files per speakers)
features = np.asarray(())
for path in file_paths:
path = path.strip()
path = path.replace('\\','/')
print(source+path)
# read the audio
sr,audio = read(source+path)
# sr = read(source + path)
# extract 40 dimensional MFCC & delta MFCC features
vector = extract_features(audio,sr)
if features.size == 0:
features = vector
else:
features = np.vstack((features, vector))
# when features of 5 files of speaker are concatenated, then do model training
if count == 5:
gmm = GMM(n_components = 16, max_iter = 200, covariance_type='diag',n_init = 3)
gmm.fit(features)
# dumping the trained gaussian model
picklefile = path.split("-")[0]+".gmm"
pickle.dump(gmm,open(dest + picklefile,'wb'))
print('+ modeling completed for speaker:',picklefile," with data point = ",features.shape)
features = np.asarray(())
count = 0
count = count + 1
我是机器学习的初学者
目前没有回答
相关问题 更多 >
编程相关推荐