bofenghuang commited on
Commit
fe32065
β€’
1 Parent(s): 694d4c4

add streaming mode

Browse files
Files changed (4) hide show
  1. README.md +3 -3
  2. app.py +18 -8
  3. packages.txt +1 -0
  4. requirements.txt +4 -0
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Tmp
3
- emoji: πŸ“‰
4
- colorFrom: gray
5
  colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.9
 
1
  ---
2
+ title: Automatic Speech Recognition in French
3
+ emoji: πŸ‘‚
4
+ colorFrom: blue
5
  colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.9
app.py CHANGED
@@ -3,16 +3,26 @@ import gradio as gr
3
 
4
  pipe = pipeline(model="bhuang/wav2vec2-xls-r-1b-cv9-fr")
5
 
6
- def transcribe(audio):
7
- text = pipe(audio)["text"]
8
- return text
 
9
 
10
  iface = gr.Interface(
11
  fn=transcribe,
12
- inputs=gr.Audio(source="microphone", type="filepath", label="Record something..."),
13
- outputs="text",
14
- title="Automatic Speech Recognition in French",
15
- description="Realtime demo for French automatic speech recognition using a fine-tuned wav2vec2 model.",
 
 
 
 
 
 
 
 
16
  )
17
 
18
- iface.launch()
 
 
3
 
4
  pipe = pipeline(model="bhuang/wav2vec2-xls-r-1b-cv9-fr")
5
 
6
+ def transcribe(audio, state=""):
7
+ text = pipe(audio, chunk_length_s=5, stride_length_s=1)["text"]
8
+ state += text + " "
9
+ return state, state
10
 
11
  iface = gr.Interface(
12
  fn=transcribe,
13
+ inputs=[
14
+ gr.Audio(source="microphone", type="filepath", streaming=True, label="Record something..."),
15
+ "state"
16
+ ],
17
+ outputs=[
18
+ "textbox",
19
+ "state"
20
+ ],
21
+ title="Realtime ASR in French",
22
+ # description="Realtime demo for French ASR using a fine-tuned wav2vec2 model.",
23
+ allow_flagging="never",
24
+ live=True
25
  )
26
 
27
+ # iface.launch()
28
+ iface.launch(server_name="0.0.0.0", share=True)
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ pyctcdecode
4
+ pypi-kenlm