XDHDD commited on
Commit
59f04fa
1 Parent(s): 28b8f93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -1
app.py CHANGED
@@ -9,6 +9,9 @@ import onnxruntime, onnx
9
  import matplotlib.pyplot as plt
10
  import numpy as np
11
  from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
 
 
 
12
 
13
  @st.cache
14
  def load_model():
@@ -119,4 +122,90 @@ if st.button('Сгенерировать потери'):
119
  st.text('Аудио с потерями')
120
  st.audio('lossy.wav')
121
  st.text('Улучшенное аудио')
122
- st.audio('enhanced.wav')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  import matplotlib.pyplot as plt
10
  import numpy as np
11
  from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
12
+ from torchmetrics.audio import ShortTimeObjectiveIntelligibility as STOI
13
+ from torchmetrics.audio.pesq import PerceptualEvaluationSpeechQuality as PESQ
14
+ import pandas as pd
15
 
16
  @st.cache
17
  def load_model():
 
122
  st.text('Аудио с потерями')
123
  st.audio('lossy.wav')
124
  st.text('Улучшенное аудио')
125
+ st.audio('enhanced.wav')
126
+ data_clean, samplerate = torchaudio.load('target.wav')
127
+
128
+ data_lossy, samplerate = torchaudio.load('lossy.wav')
129
+ data_enhanced, samplerate = torchaudio.load('enhanced.wav')
130
+ min_len = min(data_clean.shape[1], data_lossy.shape[1])
131
+ data_clean = data_clean[:, :min_len]
132
+ data_lossy = data_lossy[:, :min_len]
133
+ data_enhanced = data_enhanced[:, :min_len]
134
+
135
+
136
+ stoi = STOI(48000)
137
+ stoi_orig = np.array(stoi(data_clean, data_clean))
138
+ stoi_lossy = np.array(stoi(data_clean, data_lossy))
139
+ stoi_enhanced = np.array(stoi(data_clean, data_enhanced))
140
+ stoi_mass=[stoi_orig, stoi_lossy, stoi_enhanced]
141
+
142
+
143
+ pesq = PESQ(16000, 'nb')
144
+ data_clean = data_clean.cpu().numpy()
145
+ data_lossy = data_lossy.detach().cpu().numpy()
146
+ data_enhanced = data_enhanced.cpu().numpy()
147
+
148
+ if samplerate != 16000:
149
+ data_lossy = librosa.resample(data_lossy, orig_sr=48000, target_sr=16000)
150
+ data_clean = librosa.resample(data_clean, orig_sr=48000, target_sr=16000)
151
+ data_enhanced = librosa.resample(data_enhanced, orig_sr=48000, target_sr=16000)
152
+
153
+ pesq_orig = np.array(pesq(torch.tensor(data_clean), torch.tensor(data_clean)))
154
+ pesq_lossy = np.array(pesq(torch.tensor(data_lossy), torch.tensor(data_clean)))
155
+ pesq_enhanced = np.array(pesq(torch.tensor(data_enhanced), torch.tensor(data_clean)))
156
+
157
+ psq_mas=[pesq_orig, pesq_lossy, pesq_enhanced]
158
+
159
+
160
+
161
+ df = pd.DataFrame(columns=['Audio', 'PESQ', 'STOI', 'PLCMOS', 'LSD'])
162
+
163
+ df['Audio'] = ['Clean', 'Lossy', 'Enhanced']
164
+
165
+ df['PESQ'] = psq_mas
166
+
167
+ df['STOI'] = stoi_mass
168
+
169
+ st.table(df)
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+