papasega commited on
Commit
daee104
1 Parent(s): 778280c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+
5
+ transcriber = pipeline("automatic-speech-recognition", model="jonatasgrosman/wav2vec2-large-xlsr-53-arabic")
6
+
7
+ def transcribe(stream, new_chunk):
8
+ sr, y = new_chunk
9
+ y = y.astype(np.float32)
10
+ y /= np.max(np.abs(y))
11
+
12
+ if stream is not None:
13
+ stream = np.concatenate([stream, y])
14
+ else:
15
+ stream = y
16
+ return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
17
+
18
+
19
+ demo = gr.Interface(
20
+ transcribe,
21
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
22
+ ["state", "text"],
23
+ live=True, title="S2T: Transcription automatique en live de l'arabe en text by Papa Séga",
24
+ description="Utilisez le microphone pour parler en arabe et la transcription démarre en quelques secondes"
25
+ )
26
+
27
+
28
+ demo.launch()