File size: 2,381 Bytes
af8c3ac
248b73a
af8c3ac
 
 
 
 
 
 
248b73a
 
 
 
 
 
af8c3ac
 
248b73a
 
af8c3ac
 
 
 
248b73a
af8c3ac
 
 
248b73a
 
 
 
 
 
 
 
af8c3ac
248b73a
 
 
 
 
 
 
 
 
 
 
af8c3ac
248b73a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65ced0b
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from transformers import pipeline
import gradio as gr
import time
p = pipeline(
            task="automatic-speech-recognition",
            model="arthoho66/model_005_2000",
            token="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",
            # device="cuda:0",
        )
text = ""
def recorded_process(recorded_audio_file) -> str:
    """ 
    to get both input 
    and use speech2text for get text
    """
    text = p(recorded_audio_file)["text"]
    return text


def streaming_process(streaming_audio_file) -> str:
    global text 
    text = p(streaming_audio_file)["text"]
    return text

def output_streaming(text_streaming,text01)-> str:
    text_streaming+=text01
    return text_streaming

def clear_inputs_and_outputs() -> list:
    """
    Clears all inputs and outputs when the user clicks "Clear" button
    """
    audio_chunk.remove_chunk()
    return [None, None, None, None]


text_streaming = ""

with gr.Blocks() as demo:
    with gr.Tab("Record File"):
        with gr.Row():  
            with gr.Column():
                mic_input = gr.Microphone( type="filepath",label="Record voice")
                with gr.Row():
                    clr_btn = gr.Button(value="Clear", variant="secondary")
                    sub_btn = gr.Button(value="submit")
            with gr.Column():
                lbl_output = gr.Textbox(label="Result")

            clr_btn.click(
                fn=clear_inputs_and_outputs,
                    inputs=[],
                    outputs=[mic_input, lbl_output]
            )

            sub_btn.click(
                fn=recorded_process,
                inputs=[mic_input],
                outputs=[lbl_output]
            )

    with gr.Tab("streaming"):
        gr.Interface(
                    fn=streaming_process,
                    inputs=[
                        gr.Microphone(type="filepath", streaming=True)],
                    outputs=[
                    #     # gr.HighlightedText(label="Result"),
                        gr.Textbox(type ="text", label="Result",)],
                    live=True,
                    allow_flagging="never"
                    )
        with gr.Row():  
            with gr.Column():
                print(text)
                text_streaming = output_streaming(text_streaming,text)
                gr.Textbox(value=text, label="Result", autofocus=True)

demo.launch()