Spaces:
Runtime error
Runtime error
Commit
·
14f3ee2
1
Parent(s):
25614eb
Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,23 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
10 |
model = CombinedModel("facebook/mms-1b-all", "Sunbird/sunbird-mul-en-mbart-merged", device=device)
|
11 |
|
12 |
def transcribe(audio_file_mic=None, audio_file_upload=None):
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
description = '''Luganda to English Speech Translation'''
|
17 |
|
|
|
10 |
model = CombinedModel("facebook/mms-1b-all", "Sunbird/sunbird-mul-en-mbart-merged", device=device)
|
11 |
|
12 |
def transcribe(audio_file_mic=None, audio_file_upload=None):
|
13 |
+
if audio_file_mic:
|
14 |
+
audio_file = audio_file_mic
|
15 |
+
elif audio_file_upload:
|
16 |
+
audio_file = audio_file_upload
|
17 |
+
else:
|
18 |
+
return "Please upload an audio file or record one"
|
19 |
+
|
20 |
+
# Make sure audio is 16kHz
|
21 |
+
speech, sample_rate = librosa.load(audio_file)
|
22 |
+
if sample_rate != 16000:
|
23 |
+
speech = librosa.resample(speech, orig_sr=sample_rate, target_sr=16000)
|
24 |
+
speech = torch.tensor([speech])
|
25 |
+
|
26 |
+
with torch.no_grad():
|
27 |
+
transcription, translation = model({"audio": speech})
|
28 |
+
|
29 |
+
return transcription, translation[0]
|
30 |
|
31 |
description = '''Luganda to English Speech Translation'''
|
32 |
|