Spaces:
Runtime error
Runtime error
Add-Vishnu
commited on
Commit
•
2153fc6
1
Parent(s):
2730f3a
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
from transformers import pipeline
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import librosa
|
6 |
+
|
7 |
+
pipe2 = pipeline("automatic-speech-recognition", model="ai4bharat/indicwav2vec-hindi")
|
8 |
+
|
9 |
+
def resample_to_16k(audio, orig_sr):
|
10 |
+
y_resampled = librosa.resample(y=audio, orig_sr=orig_sr, target_sr=16000)
|
11 |
+
return y_resampled
|
12 |
+
|
13 |
+
def transcribe(audio):
|
14 |
+
sr,y = audio
|
15 |
+
y = y.astype(np.float32)
|
16 |
+
y/= np.max(np.abs(y))
|
17 |
+
y_resampled = resample_to_16k(y,sr)
|
18 |
+
|
19 |
+
trans = pipe2(y_resampled)
|
20 |
+
|
21 |
+
return trans["text"]
|
22 |
+
|
23 |
+
demo = gr.Interface(
|
24 |
+
transcribe,
|
25 |
+
inputs="microphone",
|
26 |
+
outputs="text",
|
27 |
+
examples=["./Samples/Hindi_1.mp3","./Samples/Hindi_2.mp3","./Samples/Hindi_3.mp3","./Samples/Hindi_4.mp3","./Samples/Hindi_5.mp3"])
|
28 |
+
demo.launch()
|