Spaces:
Runtime error
Runtime error
Commit ·
4823961
1
Parent(s): 3a9d48c
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import numpy as np
|
| 5 |
+
import librosa
|
| 6 |
+
|
| 7 |
+
transcriber_hindi = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec-hindi")
|
| 8 |
+
transcriber_bengali = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec_v1_bengali")
|
| 9 |
+
transcriber_odia = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec-odia")
|
| 10 |
+
transcriber_gujarati = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec_v1_gujarati")
|
| 11 |
+
transcriber_telugu = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec_v1_telugu")
|
| 12 |
+
transcriber_sinhala = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec_v1_sinhala")
|
| 13 |
+
transcriber_tamil = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec_v1_tamil")
|
| 14 |
+
transcriber_nepali = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec_v1_nepali")
|
| 15 |
+
transcriber_marathi = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec_v1_marathi")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def resample_to_16k(audio, orig_sr):
|
| 19 |
+
y_resampled = librosa.resample(y=audio, orig_sr=orig_sr, target_sr=16000)
|
| 20 |
+
return y_resampled
|
| 21 |
+
|
| 22 |
+
def transcribe(audio):
|
| 23 |
+
sr,y = audio
|
| 24 |
+
y = y.astype(np.float32)
|
| 25 |
+
y/= np.max(np.abs(y))
|
| 26 |
+
y_resampled = resample_to_16k(y,sr)
|
| 27 |
+
|
| 28 |
+
pipe= eval(f'transcriber_{lang}')
|
| 29 |
+
trans = pipe(y_resampled)
|
| 30 |
+
|
| 31 |
+
return trans["text"]
|
| 32 |
+
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
transcribe,
|
| 35 |
+
inputs=["microphone",gr.Radio(["hindi","bangali","odia","gujarati","telugu","sinhala","tamil","nepali","marathi"],value="hindi")],
|
| 36 |
+
outputs="text",
|
| 37 |
+
examples=[["./Samples/Hindi_1.mp3","hindi"],["./Samples/Hindi_2.mp3","hindi"],["./Samples/Tamil_1.mp3","tamil"],["./Samples/Tamil_2.mp3","hindi"],["./Samples/Nepal_1.mp3","nepali"],["./Samples/Nepal_2.mp3","nepali"],["./Samples/Marathi_1.mp3","marathi"],["./Samples/Marathi_2.mp3","marathi"],["./Samples/climate ex short.wav","hindi"]])
|
| 38 |
+
demo.launch()
|