Spaces:
Sleeping
Sleeping
added try except in test
Browse files
server.py
CHANGED
@@ -39,44 +39,41 @@ def delFiles():
|
|
39 |
|
40 |
|
41 |
async def predictor(names, file_uploads, usersNum, recordingsNum):
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
print("error ", e)
|
71 |
-
except Exception as e:
|
72 |
-
print("function error ", e)
|
73 |
|
74 |
# make a list of the pre-processed audios ki arrays
|
75 |
for sp_wvs in speaker_wavs_list:
|
76 |
speaker_embed_list.append(
|
77 |
np.array([encoder.embed_speaker(wavs) for wavs in sp_wvs.values()]))
|
78 |
|
79 |
-
|
80 |
# making preprocessed test audio
|
81 |
wav_fpaths = []
|
82 |
file_upload = file_uploads[-1]
|
@@ -87,11 +84,14 @@ async def predictor(names, file_uploads, usersNum, recordingsNum):
|
|
87 |
file_object.write(data)
|
88 |
wav_fpaths.append(Path(file_path))
|
89 |
print("about to test\n")
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
95 |
|
96 |
# calculates cosine similarity between the ground truth (test file) and registered audios
|
97 |
speakers = {}
|
|
|
39 |
|
40 |
|
41 |
async def predictor(names, file_uploads, usersNum, recordingsNum):
|
42 |
+
speaker_embed_list = []
|
43 |
+
encoder = VoiceEncoder()
|
44 |
+
# Iterating over list of files corresponding to each user
|
45 |
+
speaker_wavs_list = []
|
46 |
+
fileInd = 0
|
47 |
+
names.pop() # to remove key named "test"
|
48 |
+
print("file_uploads ", file_uploads, "recordingNums ", recordingsNum)
|
49 |
+
for name in names:
|
50 |
+
wav_fpaths = []
|
51 |
+
for ind in range(int(recordingsNum)):
|
52 |
+
print("inside yo")
|
53 |
+
file_upload = file_uploads[fileInd]
|
54 |
+
data = await file_upload.read()
|
55 |
+
# appending person's name to the his/her recordings
|
56 |
+
filename = name+"¬"+file_upload.filename
|
57 |
+
file_path = UPLOAD_DIR / filename
|
58 |
+
with open(file_path, "wb") as file_object:
|
59 |
+
file_object.write(data)
|
60 |
+
wav_fpaths.append(Path(file_path))
|
61 |
+
fileInd += 1
|
62 |
+
print("wav_fpaths len", len(wav_fpaths), "name", name)
|
63 |
+
try:
|
64 |
+
speaker_wavs = {speaker: list(map(preprocess_wav, wav_fpaths)) for speaker, wav_fpaths in
|
65 |
+
groupby(tqdm(wav_fpaths, "Preprocessing wavs", len(wav_fpaths), unit="wavs"),
|
66 |
+
lambda wav_fpath: os.path.basename(wav_fpath).split("¬")[0])} # extracting person's name from file name
|
67 |
+
speaker_wavs_list.append(speaker_wavs)
|
68 |
+
except Exception as e:
|
69 |
+
print("error ", e)
|
|
|
|
|
|
|
70 |
|
71 |
# make a list of the pre-processed audios ki arrays
|
72 |
for sp_wvs in speaker_wavs_list:
|
73 |
speaker_embed_list.append(
|
74 |
np.array([encoder.embed_speaker(wavs) for wavs in sp_wvs.values()]))
|
75 |
|
76 |
+
print("preprocessed audio ki array ", speaker_embed_list)
|
77 |
# making preprocessed test audio
|
78 |
wav_fpaths = []
|
79 |
file_upload = file_uploads[-1]
|
|
|
84 |
file_object.write(data)
|
85 |
wav_fpaths.append(Path(file_path))
|
86 |
print("about to test\n")
|
87 |
+
try:
|
88 |
+
test_pos_wavs = {speaker: list(map(preprocess_wav, wav_fpaths)) for speaker, wav_fpaths in
|
89 |
+
groupby(tqdm(wav_fpaths, "Preprocessing wavs", len(wav_fpaths), unit="wavs"),
|
90 |
+
lambda wav_fpath: "test")}
|
91 |
+
test_pos_emb = np.array([encoder.embed_speaker(wavs)
|
92 |
+
for wavs in test_pos_wavs.values()])
|
93 |
+
except Exception as error:
|
94 |
+
print("test error ", error)
|
95 |
|
96 |
# calculates cosine similarity between the ground truth (test file) and registered audios
|
97 |
speakers = {}
|