peterkros commited on
Commit
f0d0884
·
verified ·
1 Parent(s): 4ca61bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -13,11 +13,14 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
13
  model.to(device)
14
 
15
  def transcribe(audio):
16
- # Gradio passes audio as a numpy array, so no need to load from file.
17
- # If the input is a file path, load the audio from the file:
18
  if isinstance(audio, str): # Assuming it's a file path
19
  audio, sampling_rate = sf.read(audio)
20
 
 
 
 
 
21
  # Process the audio to get input features
22
  input_features = processor(audio, sampling_rate=16000, return_tensors="pt").input_features.to(device)
23
 
 
13
  model.to(device)
14
 
15
  def transcribe(audio):
16
+ # Check if the input is a file path and load the audio from the file
 
17
  if isinstance(audio, str): # Assuming it's a file path
18
  audio, sampling_rate = sf.read(audio)
19
 
20
+ # If the audio has more than one channel, convert it to mono by averaging the channels
21
+ if len(audio.shape) > 1:
22
+ audio = audio.mean(axis=1)
23
+
24
  # Process the audio to get input features
25
  input_features = processor(audio, sampling_rate=16000, return_tensors="pt").input_features.to(device)
26