Atom007 commited on
Commit
654cca5
β€’
1 Parent(s): 9cd3122
Files changed (3) hide show
  1. Temp.mp3 +0 -0
  2. app.py +50 -0
  3. requirements.txt +3 -0
Temp.mp3 ADDED
Binary file (15.6 kB). View file
 
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Imports
2
+ import whisper
3
+ import gradio as gr
4
+ import warnings
5
+ from gtts import gTTS
6
+
7
+ model = whisper.load_model("base")
8
+
9
+
10
+ def transcribe(audio):
11
+ language = 'en'
12
+
13
+ audio = whisper.load_audio(audio)
14
+ audio = whisper.pad_or_trim(audio)
15
+
16
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
17
+
18
+ _, probs = model.detect_language(mel)
19
+ print(f"Detected language: {max(probs, key=probs.get)}")
20
+
21
+ options = whisper.DecodingOptions(fp16 = False)
22
+ result = whisper.decode(model, mel, options)
23
+ result_text = result.text
24
+ result_tr = model.transcribe(audio ,task='translate')
25
+
26
+ audioobj = gTTS(text = result_tr['text'],
27
+ lang = language,
28
+ slow = False)
29
+
30
+ audioobj.save("Temp.mp3")
31
+
32
+ return [result_text, result_tr['text'], "Temp.mp3"]
33
+
34
+
35
+ output_1 = gr.Textbox(label="Speech to Text")
36
+ output_2 = gr.Textbox(label="English Translation Output")
37
+ output_3 = gr.Audio("Temp.mp3", label="English Audio")
38
+
39
+ gr.Interface(
40
+ title = 'OpenAI Whisper ASR and Translation Gradio Web UI',
41
+ fn=transcribe,
42
+ inputs=[
43
+ # gr.inputs.Audio(source="microphone", type="filepath"),
44
+ gr.Audio(source="upload", type="filepath")
45
+ ],
46
+
47
+ outputs=[
48
+ output_1, output_2, output_3
49
+ ],
50
+ live=True).launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow
2
+ git+https://github.com/openai/whisper.git
3
+ gTTS