Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,10 @@ import pandas as pd
|
|
| 16 |
import torchaudio
|
| 17 |
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
@st.cache
|
| 21 |
def load_model():
|
|
@@ -128,7 +132,52 @@ if st.button('Сгенерировать потери'):
|
|
| 128 |
st.text('Улучшенное аудио')
|
| 129 |
st.audio('enhanced.wav')
|
| 130 |
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
data_clean, samplerate = sf.read('target.wav')
|
| 133 |
data_lossy, samplerate = sf.read('lossy.wav')
|
| 134 |
data_enhanced, samplerate = sf.read('enhanced.wav')
|
|
|
|
| 16 |
import torchaudio
|
| 17 |
|
| 18 |
|
| 19 |
+
from torchmetrics.audio import ShortTimeObjectiveIntelligibility as STOI
|
| 20 |
+
from torchmetrics.audio.pesq import PerceptualEvaluationSpeechQuality as PESQ
|
| 21 |
+
|
| 22 |
+
|
| 23 |
|
| 24 |
@st.cache
|
| 25 |
def load_model():
|
|
|
|
| 132 |
st.text('Улучшенное аудио')
|
| 133 |
st.audio('enhanced.wav')
|
| 134 |
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
data_clean, samplerate = torchaudio.load('/content/Катя_базу_выдала.wav')
|
| 141 |
+
data_lossy, samplerate = torchaudio.load('/content/Катя_базу_выдала_40%.wav')
|
| 142 |
+
data_enhanced, samplerate = torchaudio.load('/content/Катя_базу_выдала_демо.wav')
|
| 143 |
+
|
| 144 |
+
min_len = min(data_clean.shape[1], data_lossy.shape[1], data_enhanced.shape[1])
|
| 145 |
+
data_clean = data_clean[:, :min_len]
|
| 146 |
+
data_lossy = data_lossy[:, :min_len]
|
| 147 |
+
data_enhanced = data_enhanced[:, :min_len]
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
stoi = STOI(samplerate)
|
| 151 |
+
|
| 152 |
+
stoi_orig = round(float(stoi(data_clean, data_clean)),3)
|
| 153 |
+
stoi_lossy = round(float(stoi(data_clean, data_lossy)),5)
|
| 154 |
+
stoi_enhanced = round(float(stoi(data_clean, data_enhanced)),5)
|
| 155 |
+
|
| 156 |
+
stoi_mass=[stoi_orig, stoi_lossy, stoi_enhanced]
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
pesq = PESQ(16000, 'nb')
|
| 160 |
+
|
| 161 |
+
data_clean = data_clean.cpu().numpy()
|
| 162 |
+
data_lossy = data_lossy.cpu().numpy()
|
| 163 |
+
data_enhanced = data_enhanced.cpu().numpy()
|
| 164 |
+
|
| 165 |
+
if samplerate != 16000:
|
| 166 |
+
data_lossy = librosa.resample(data_lossy, orig_sr=48000, target_sr=16000)
|
| 167 |
+
data_clean = librosa.resample(data_clean, orig_sr=48000, target_sr=16000)
|
| 168 |
+
data_enhanced = librosa.resample(data_enhanced, orig_sr=48000, target_sr=16000)
|
| 169 |
+
|
| 170 |
+
pesq_orig = float(pesq(torch.tensor(data_clean), torch.tensor(data_clean)))
|
| 171 |
+
pesq_lossy = float(pesq(torch.tensor(data_lossy), torch.tensor(data_clean)))
|
| 172 |
+
pesq_enhanced = float(pesq(torch.tensor(data_enhanced), torch.tensor(data_clean)))
|
| 173 |
+
|
| 174 |
+
psq_mas=[pesq_orig, pesq_lossy, pesq_enhanced]
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
#_____________________________________________
|
| 181 |
data_clean, samplerate = sf.read('target.wav')
|
| 182 |
data_lossy, samplerate = sf.read('lossy.wav')
|
| 183 |
data_enhanced, samplerate = sf.read('enhanced.wav')
|