NuMessiah commited on
Commit
36e6932
·
1 Parent(s): e9565b7

Convert to mono

Browse files
Files changed (1) hide show
  1. app.py +4 -0
app.py CHANGED
@@ -25,6 +25,10 @@ def transcribe_audio(audio_file):
25
  resampler = torchaudio.transforms.Resample(sample_rate, 16000)
26
  audio = resampler(audio)
27
 
 
 
 
 
28
  # Transcribe the audio
29
  transcription = whisper_pipeline(audio.squeeze().numpy())["text"] # .squeeze() removes extra dimensions
30
 
 
25
  resampler = torchaudio.transforms.Resample(sample_rate, 16000)
26
  audio = resampler(audio)
27
 
28
+ # Convert to Mono
29
+ if audio.shape[0] > 1: # Check if multi-channel
30
+ audio = torch.mean(audio, dim=0, keepdim=True) # Average channels
31
+
32
  # Transcribe the audio
33
  transcription = whisper_pipeline(audio.squeeze().numpy())["text"] # .squeeze() removes extra dimensions
34