-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGenerate_PS_Feature.py
81 lines (62 loc) · 2.01 KB
/
Generate_PS_Feature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
71
72
73
74
75
76
77
78
79
80
81
"""
@author: Ryandhimas Zezario
"""
import sys
import scipy.io
import librosa
import os
import time
import numpy as np
import numpy.matlib
import random
import pdb
random.seed(999)
def ListRead(filelist):
f = open(filelist, 'r')
Path=[]
for line in f:
Path=Path+[line[0:-1]]
return Path
def Save_Npy_PS(filepath,list_new ):
Noisy=False
path = filepath [3]
S=path.split('/')
wave_name=S[-1]
name = wave_name[:-4]
dir_ = S[-1]
new_name = name +'.npy'
cached_path = os.path.join("/DIR/PS/"+dir_,new_name)
signal, rate = librosa.load(path,sr=16000)
signal=signal/np.max(abs(signal))
F = librosa.stft(signal,n_fft=512,hop_length=256,win_length=512,window=scipy.signal.hamming)
Lp=np.abs(F)
phase=np.angle(F)
if Noisy==True:
meanR = np.mean(Lp, axis=1).reshape((257,1))
stdR = np.std(Lp, axis=1).reshape((257,1))+1e-12
NLp = (Lp-meanR)/stdR
else:
NLp=Lp
NLp=np.reshape(NLp.T,(1,NLp.shape[1],257))
np.save(cached_path,NLp)
info = filepath[0]+','+filepath[1]+','+filepath[2]+','+str(cached_path)
list_new.append(info)
return list_new
def extracting_PS_features(file_list):
list_new=[]
for index in range(len(file_list)):
filepath = file_list[index].split(',')
list_new=Save_Npy_PS(filepath, list_new)
with open('List_Npy_Train_PS.txt','w') as g:
for item in list_new:
g.write("%s\n" % item)
if __name__ == '__main__':
print 'Extracting PS Features...'
Enhanced_list = ListRead('EnhAllDataList_PESQ_STOI_SDI.txt')
Noisy_list = ListRead('NoisyList_PESQ_STOI_SDI.txt')
Clean_list = ListRead('CleanList_PESQ_STOI_SDI.txt')
Enhanced_noisy_list=Enhanced_list+Noisy_list
Train_list= Enhanced_noisy_list+Clean_list
random.shuffle(Train_list)
extracting_PS_features(Train_list)