rutsam commited on
Commit
deae7d5
1 Parent(s): 8d7ba4e

deploy app

Browse files
Files changed (3) hide show
  1. app.py +37 -0
  2. packages.txt +3 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import nemo.collections.asr as nemo_asr
3
+ from pydub import AudioSegment
4
+ import pyaudioconvert as pac
5
+
6
+
7
+ hf_model = nemo_asr.models.EncDecRNNTBPEModel.from_pretrained(
8
+ model_name="mbazaNLP/stt_rw_sw_lg_conformer_ctc_large")
9
+
10
+ def convert (audio):
11
+ file_name = audio.name
12
+ if file_name.endswith("mp3") or file_name.endswith("wav") or file_name.endswith("ogg"):
13
+ if file_name.endswith("mp3"):
14
+ sound = AudioSegment.from_mp3(audio.name)
15
+ sound.export(audio.name, format="wav")
16
+ elif file_name.endswith("ogg"):
17
+ sound = AudioSegment.from_ogg(audio.name)
18
+ sound.export(audio.name, format="wav")
19
+ else:
20
+ return False
21
+ pac.convert_wav_to_16bit_mono(audio.name,audio.name)
22
+ return True
23
+
24
+ def transcribe(audio, audio_microphone):
25
+ audio = audio_microphone if audio_microphone else audio
26
+ if convert(audio)== False:
27
+ return "The format must be mp3,wav and ogg"
28
+ result= hf_model.transcribe([audio.name])
29
+ return result[0]
30
+ gradio_ui = gr.Interface(
31
+ fn=transcribe,
32
+ title="East african languages Speech Recognition",
33
+ description="Upload an audio clip or record from browser using microphone, and let AI do the hard work of transcribing. The supported languages are Kinyarwanda, Swahili and Luganda",
34
+ inputs=[gr.inputs.Audio(label="Upload Audio File", type="file", optional=True), gr.inputs.Audio(source="microphone", type="file", optional=True, label="Record from microphone")],
35
+ outputs=[gr.outputs.Textbox(label="Recognized speech")]
36
+ )
37
+ gradio_ui.launch(enable_queue=True)
packages.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ libsndfile1
2
+ ffmpeg
3
+ sox
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pydub
2
+ pyaudioconvert
3
+ nemo_toolkit[asr]