Spaces:
Runtime error
Runtime error
deploy new code
Browse files- app.py +31 -3
- package.txt +3 -0
- requirements.txt +4 -1
app.py
CHANGED
@@ -1,7 +1,35 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import nemo.collections.asr as nemo_asr
|
3 |
+
from pydub import AudioSegment
|
4 |
+
import pyaudioconvert as pac
|
5 |
+
import timeit
|
6 |
|
7 |
+
hf_model = nemo_asr.models.EncDecRNNTBPEModel.from_pretrained(
|
8 |
+
model_name="mbazaNLP/Kinyarwanda_nemo_stt_conformer_model")
|
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):
|
25 |
+
start = timeit.default_timer()
|
26 |
+
if convert(audio)== False:
|
27 |
+
return "The format must be mp3,wav and ogg"
|
28 |
+
|
29 |
+
files = [audio.name]
|
30 |
+
print(audio.name)
|
31 |
+
for fname, transcription in zip(files, hf_model.transcribe(paths2audio_files=files)):
|
32 |
+
stop = timeit.default_timer()
|
33 |
+
return "message"+ transcription[0]+ "\nfilename"+ audio.name+"\nTrancriptionTime"+stop-start
|
34 |
+
|
35 |
+
gradio_ui.launch()
|
package.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
libsndfile1
|
2 |
+
ffmpeg
|
3 |
+
sox
|
requirements.txt
CHANGED
@@ -1 +1,4 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
1 |
+
pydub
|
2 |
+
pyaudioconvert
|
3 |
+
nemo_toolkit[asr]
|
4 |
+
gradio
|