bofenghuang commited on
Commit
f0b2cfd
β€’
1 Parent(s): d925c7e

switch to non-streaming mode

Browse files
Files changed (5) hide show
  1. README.md +1 -1
  2. app.py +0 -28
  3. app.py +1 -0
  4. run_demo.py +22 -0
  5. run_demo_streaming.py +24 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Realtime ASR in French
3
  emoji: πŸ‘‚
4
  colorFrom: green
5
  colorTo: indigo
 
1
  ---
2
+ title: Speech-to-Text in French
3
  emoji: πŸ‘‚
4
  colorFrom: green
5
  colorTo: indigo
app.py DELETED
@@ -1,28 +0,0 @@
1
- from transformers import pipeline
2
- import gradio as gr
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
- # streaming mode
12
- iface = gr.Interface(
13
- fn=transcribe,
14
- inputs=[
15
- gr.Audio(source="microphone", type="filepath", streaming=True, label="Record something..."),
16
- "state"
17
- ],
18
- outputs=[
19
- "textbox",
20
- "state"
21
- ],
22
- title="Realtime ASR in French",
23
- # description="Realtime demo for French ASR using a fine-tuned wav2vec2 model.",
24
- allow_flagging="never",
25
- live=True
26
- )
27
-
28
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1 @@
 
 
1
+ run_demo.py
run_demo.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ pipe = pipeline(model="bhuang/wav2vec2-xls-r-1b-cv9-fr")
5
+
6
+
7
+ def transcribe(audio):
8
+ # text = pipe(audio, chunk_length_s=30, stride_length_s=5)["text"]
9
+ text = pipe(audio)["text"]
10
+ return text
11
+
12
+
13
+ iface = gr.Interface(
14
+ fn=transcribe,
15
+ inputs=gr.Audio(source="microphone", type="filepath", label="Record something..."),
16
+ outputs="text",
17
+ title="Speech-to-Text in French",
18
+ description="Realtime demo for French automatic speech recognition.",
19
+ allow_flagging="never",
20
+ )
21
+
22
+ iface.launch()
run_demo_streaming.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ pipe = pipeline(model="bhuang/wav2vec2-xls-r-1b-cv9-fr")
5
+
6
+
7
+ def transcribe(audio, state=""):
8
+ text = pipe(audio, chunk_length_s=5, stride_length_s=1)["text"]
9
+ state += text + " "
10
+ return state, state
11
+
12
+
13
+ # streaming mode
14
+ iface = gr.Interface(
15
+ fn=transcribe,
16
+ inputs=[gr.Audio(source="microphone", type="filepath", streaming=True, label="Record something..."), "state"],
17
+ outputs=["textbox", "state"],
18
+ title="Realtime Speech-to-Text in French",
19
+ description="Realtime demo for French automatic speech recognition.",
20
+ allow_flagging="never",
21
+ live=True,
22
+ )
23
+
24
+ iface.launch()