Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
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 |
|