anzorq commited on
Commit
b20428c
1 Parent(s): 1f1ae63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -32,8 +32,11 @@ def replace_symbols_back(text):
32
  def preprocess_audio(audio_tensor, original_sample_rate, apply_normalization):
33
  audio_tensor = audio_tensor.to(dtype=torch.float32)
34
  audio_tensor = torch.mean(audio_tensor, dim=0, keepdim=True) # Convert to mono
 
35
  if apply_normalization:
36
- audio_tensor = audio_tensor / torch.max(torch.abs(audio_tensor)) # Normalize
 
 
37
  audio_tensor = torchaudio.functional.resample(audio_tensor, orig_freq=original_sample_rate, new_freq=16000) # Resample
38
  return audio_tensor
39
 
 
32
  def preprocess_audio(audio_tensor, original_sample_rate, apply_normalization):
33
  audio_tensor = audio_tensor.to(dtype=torch.float32)
34
  audio_tensor = torch.mean(audio_tensor, dim=0, keepdim=True) # Convert to mono
35
+
36
  if apply_normalization:
37
+ audio_tensor = audio_tensor / torch.max(torch.abs(audio_tensor)) # Normalize
38
+ audio_tensor = torch.clamp(audio_tensor, min=-1, max=1)
39
+
40
  audio_tensor = torchaudio.functional.resample(audio_tensor, orig_freq=original_sample_rate, new_freq=16000) # Resample
41
  return audio_tensor
42