FrexG commited on
Commit
86ff979
1 Parent(s): 9716690

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import torchaudio
4
+ import torchaudio.functional as AF
5
+ from hg_mms import Transcribe
6
+
7
+
8
+ def transcribe(audio_file, lang_id: str):
9
+ print(f"audio_file={audio_file}")
10
+ print(lang_id)
11
+ freq = 16000
12
+ # Return the transcript.
13
+ transcript = ""
14
+ # load the auido file to tensor
15
+ waveform, orig_freq = torchaudio.load(audio_file.name)
16
+ # resample audio to 16Khz
17
+ if orig_freq != freq:
18
+ waveform = AF.resample(waveform, orig_freq, freq)
19
+
20
+ return transcriber(waveform, lang_id), audio_file.name
21
+
22
+ if __name__ == "__main__":
23
+ transcriber = Transcribe()
24
+ inputs = [gr.File(), gr.Dropdown(choices=["amh", "orm", "som"])]
25
+ outputs = [
26
+ gr.Textbox(label="Transcript"),
27
+ gr.Audio(label="Audio", type="filepath"),
28
+ ]
29
+
30
+ app = gr.Interface(transcribe, inputs=inputs, outputs=outputs)
31
+ app.launch()