XDHDD commited on
Commit
c9e9d08
1 Parent(s): a75efa2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -29
app.py CHANGED
@@ -10,8 +10,8 @@ from dataset import MaskGenerator
10
  import onnxruntime, onnx
11
  import matplotlib.pyplot as plt
12
  from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
13
- from torchmetrics.audio.stoi import ShortTimeObjectiveIntelligibility as STOI
14
- from torchmetrics.audio.pesq import PerceptualEvaluationSpeechQuality as PESQ
15
  import pandas as pd
16
  import torchaudio
17
 
@@ -125,38 +125,34 @@ if st.button('Сгенерировать потери'):
125
  st.audio('lossy.wav')
126
  st.text('Улучшенное аудио')
127
  st.audio('enhanced.wav')
128
- data_clean, samplerate = torchaudio.load('target.wav')
129
 
130
- data_lossy, samplerate = torchaudio.load('lossy.wav')
131
- data_enhanced, samplerate = torchaudio.load('enhanced.wav')
132
- min_len = min(data_clean.shape[1], data_lossy.shape[1], data_enhanced.shape[1])
133
- data_clean = data_clean[:, :min_len]
134
- data_lossy = data_lossy[:, :min_len]
135
- data_enhanced = data_enhanced[:, :min_len]
136
-
137
-
138
- stoi = STOI(samplerate)
139
- stoi_orig = round(float(stoi(data_clean, data_clean)),3)
140
- stoi_lossy = round(float(stoi(data_clean, data_lossy)),5)
141
- stoi_enhanced = round(float(stoi(data_clean, data_enhanced)),5)
 
 
142
  stoi_mass=[stoi_orig, stoi_lossy, stoi_enhanced]
143
 
144
 
145
- #pesq = PESQ(16000, 'nb')
146
- #data_clean = data_clean.cpu().numpy()
147
- #data_lossy = data_lossy.detach().cpu().numpy()
148
- #data_enhanced = data_enhanced.cpu().numpy()
149
-
150
- #if samplerate != 16000:
151
- # data_lossy = librosa.resample(data_lossy, orig_sr=48000, target_sr=16000)
152
- # data_clean = librosa.resample(data_clean, orig_sr=48000, target_sr=16000)
153
- # data_enhanced = librosa.resample(data_enhanced, orig_sr=48000, target_sr=16000)
154
 
155
- # pesq_orig = np.array(pesq(torch.tensor(data_clean), torch.tensor(data_clean)))
156
- # pesq_lossy = np.array(pesq(torch.tensor(data_lossy), torch.tensor(data_clean)))
157
- # pesq_enhanced = np.array(pesq(torch.tensor(data_enhanced), torch.tensor(data_clean)))
158
 
159
- #psq_mas=[pesq_orig, pesq_lossy, pesq_enhanced]
160
 
161
 
162
 
@@ -164,7 +160,7 @@ if st.button('Сгенерировать потери'):
164
 
165
  df['Audio'] = ['Clean', 'Lossy', 'Enhanced']
166
 
167
- #df['PESQ'] = psq_mas
168
 
169
  df['STOI'] = stoi_mass
170
 
 
10
  import onnxruntime, onnx
11
  import matplotlib.pyplot as plt
12
  from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
13
+ from pystoi import stoi
14
+ from pesq import pesq
15
  import pandas as pd
16
  import torchaudio
17
 
 
125
  st.audio('lossy.wav')
126
  st.text('Улучшенное аудио')
127
  st.audio('enhanced.wav')
 
128
 
129
+
130
+ data_clean, samplerate = sf.read('target.wav')
131
+ data_lossy, samplerate = sf.read('lossy.wav')
132
+ data_enhanced, samplerate = sf.read('enhanced.wav')
133
+ min_len = min(data_clean.shape[0], data_lossy.shape[0], data_enhanced.shape[0])
134
+ data_clean = data_clean[:min_len]
135
+ data_lossy = data_lossy[:min_len]
136
+ data_enhanced = data_enhanced[:min_len]
137
+
138
+
139
+ stoi_orig = round(stoi(data_clean, data_clean, samplerate, extended=False),5)
140
+ stoi_lossy = round(stoi(data_clean, data_lossy , samplerate, extended=False),5)
141
+ stoi_enhanced = round(stoi(data_clean, data_enhanced, samplerate, extended=False),5)
142
+
143
  stoi_mass=[stoi_orig, stoi_lossy, stoi_enhanced]
144
 
145
 
146
+ if samplerate != 16000:
147
+ data_lossy = librosa.resample(data_lossy, orig_sr=48000, target_sr=16000)
148
+ data_clean = librosa.resample(data_clean, orig_sr=48000, target_sr=16000)
149
+ data_enhanced = librosa.resample(data_enhanced, orig_sr=48000, target_sr=16000)
 
 
 
 
 
150
 
151
+ pesq_orig = pesq(fs = 16000, ref = data_clean, deg = data_clean, mode='nb')
152
+ pesq_lossy = pesq(fs = 16000, ref = data_clean, deg = data_lossy, mode='nb')
153
+ pesq_enhanced = pesq(fs = 16000, ref = data_clean, deg = data_enhanced, mode='nb')
154
 
155
+ psq_mas=[pesq_orig, pesq_lossy, pesq_enhanced]
156
 
157
 
158
 
 
160
 
161
  df['Audio'] = ['Clean', 'Lossy', 'Enhanced']
162
 
163
+ df['PESQ'] = psq_mas
164
 
165
  df['STOI'] = stoi_mass
166