File size: 1,592 Bytes
f725323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from transformers import pipeline
import gradio as gr
import time

p = pipeline("automatic-speech-recognition",model="jonatasgrosman/wav2vec2-large-xlsr-53-spanish")
pc = pipeline("automatic-speech-recognition",model="softcatala/wav2vec2-large-xlsr-catala")
pe = pipeline("automatic-speech-recognition",model="jonatasgrosman/wav2vec2-large-xlsr-53-english")




def transcribe(language,audio, state=""):#language="Spanish",
    time.sleep(2)
    if language=="Spanish":
        state=""
        text = p(audio)["text"]
    if language=="Catalan":
        state=""
        text = pc(audio)["text"]
    if language=="English":
        state=""
        text = pe(audio)["text"]
    state += text + " "
    #text2="Esto es loq ue te he entendido"
    return state, state

demo=gr.Interface(
    fn=transcribe, 
    
    title="TEDCAS Offline Speech recognition",
    description="1)Select language 2)Click on 'record from microphone' and talk 3)Click on 'stop recording' 4)Click on submit 5)Before starting again, click on 'clear'",

    inputs=[
        gr.Dropdown(["Spanish","Catalan","English"]),
        #gr.Audio(source="microphone", type="filepath", streaming=True), 
        gr.inputs.Audio(source="microphone", type="filepath"), 
        "state"#,"language"
    ],
    outputs=[
        "textbox",
        "state"
    ],
    #live=True).launch()
)
demo.launch()
#gr.Interface(
#    fn=transcribe, 
#    inputs=[
#        gr.inputs.Audio(source="microphone", type="filepath"), 
#        "state"
#    ],
#    outputs=[
#        "textbox",
#        "state"
#    ],
#    live=True).launch()