3loi commited on
Commit
88ba5b7
1 Parent(s): bd1d60b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -9
app.py CHANGED
@@ -25,28 +25,20 @@ def classify_audio(audio_file):
25
  id2label = model.config.id2label
26
 
27
  sr, raw_wav = audio_file
28
-
29
- #y = raw_wav.astype(np.float32)
30
- #y /= np.max(np.abs(y))
31
-
32
  y = raw_wav.astype(np.float32, order='C') / np.iinfo(raw_wav.dtype).max
33
 
34
-
35
-
36
  output = ''
37
  if sr != 16000:
38
  y = librosa.resample(y, orig_sr=sr, target_sr=model_sr)
39
  output += "{} sampling rate is uncompatible, converted to {} as the model was trained on {} sampling rate<br>".format(sr, model_sr, model_sr)
40
-
41
 
42
 
43
  norm_wav = (y - mean) / (std+0.000001)
44
  mask = torch.ones(1, len(norm_wav))
45
  wavs = torch.tensor(norm_wav).unsqueeze(0)
46
-
47
- pred = model(wavs, mask).detach().numpy()
48
 
49
 
 
50
  for att_i, att_val in enumerate(pred[0]):
51
  output += "{}: \t{:0.4f}\n".format(id2label[att_i], att_val)
52
 
 
25
  id2label = model.config.id2label
26
 
27
  sr, raw_wav = audio_file
 
 
 
 
28
  y = raw_wav.astype(np.float32, order='C') / np.iinfo(raw_wav.dtype).max
29
 
 
 
30
  output = ''
31
  if sr != 16000:
32
  y = librosa.resample(y, orig_sr=sr, target_sr=model_sr)
33
  output += "{} sampling rate is uncompatible, converted to {} as the model was trained on {} sampling rate<br>".format(sr, model_sr, model_sr)
 
34
 
35
 
36
  norm_wav = (y - mean) / (std+0.000001)
37
  mask = torch.ones(1, len(norm_wav))
38
  wavs = torch.tensor(norm_wav).unsqueeze(0)
 
 
39
 
40
 
41
+ pred = model(wavs, mask).detach().numpy()
42
  for att_i, att_val in enumerate(pred[0]):
43
  output += "{}: \t{:0.4f}\n".format(id2label[att_i], att_val)
44