swimmiing commited on
Commit
b623c93
1 Parent(s): a8d8948

Fix audio pre-processing

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -29,13 +29,15 @@ def greet(image, audio):
29
 
30
  audio_file = torch.from_numpy(audio)
31
 
 
 
 
 
 
32
  if desired_sample_rate != sample_rate:
33
  audio_file = torchaudio.functional.resample(audio_file, sample_rate, desired_sample_rate)
34
 
35
- if audio_file.shape[0] == 2:
36
- audio_file = torch.concat([audio_file[0], audio_file[1]], dim=0) # Stereo -> mono (x2 duration)
37
-
38
- audio_file.squeeze(0)
39
 
40
  if audio_file.shape[0] > (desired_sample_rate * set_length):
41
  audio_file = audio_file[:desired_sample_rate * set_length]
 
29
 
30
  audio_file = torch.from_numpy(audio)
31
 
32
+ if len(audio_file.shape) == 2:
33
+ audio_file = torch.concat([audio_file[:, 0:1], audio_file[:, 1:2]], dim=0).T # Stereo -> mono (x2 duration)
34
+ else:
35
+ audio_file = audio_file.unsqueeze(0)
36
+
37
  if desired_sample_rate != sample_rate:
38
  audio_file = torchaudio.functional.resample(audio_file, sample_rate, desired_sample_rate)
39
 
40
+ audio_file = audio_file.squeeze(0)
 
 
 
41
 
42
  if audio_file.shape[0] > (desired_sample_rate * set_length):
43
  audio_file = audio_file[:desired_sample_rate * set_length]