surely commited on
Commit
bd7fcfa
·
1 Parent(s): 7afea48

initial commit for NepaliASR

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a pipeline as a high-level helper
2
+ from transformers import pipeline
3
+
4
+ transcriber = pipeline("automatic-speech-recognition", model="sunilregmi/whisper-small-ne-NP")
5
+
6
+ import gradio as gr
7
+ import numpy as np
8
+
9
+
10
+ def transcribe(stream, new_chunk):
11
+ sr, y = new_chunk
12
+ y = y.astype(np.float32)
13
+ y /= np.max(np.abs(y))
14
+
15
+ if stream is not None:
16
+ stream = np.concatenate([stream, y])
17
+ else:
18
+ stream = y
19
+ return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
20
+
21
+
22
+ demo = gr.Interface(
23
+ transcribe,
24
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
25
+ ["state", "text"],
26
+ live=True,
27
+ )
28
+
29
+ demo.launch()
30
+
31
+