CoolFace
Apppublic

amrelshall/Speech2Text

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py46 linesDownload Raw Back to root
1from transformers import pipeline2 3asr = pipeline(task="automatic-speech-recognition",4               model="distil-whisper/distil-small.en")5 6import gradio as gr7demo = gr.Blocks()8 9# now ho to make the demo take long time audio10def transcribe_long_form(filepath):11    if filepath is None:12        gr.Warning("Please submit again <3 ")13        return ""14    output = asr(15      filepath,16      max_new_tokens=256,17      chunk_length_s=30,18      batch_size=8,19    )20    return output["text"]21 22mic_transcribe = gr.Interface(23    fn=transcribe_long_form,24    inputs=gr.Audio(sources="microphone",25                    type="filepath"),26    outputs=gr.Textbox(label="Transcription",27                       lines=3),28    allow_flagging="never")29 30file_transcribe = gr.Interface(31    fn=transcribe_long_form,32    inputs=gr.Audio(sources="upload",33                    type="filepath"),34    outputs=gr.Textbox(label="Transcription",35                       lines=3),36    allow_flagging="never",37)38 39with demo:40    gr.TabbedInterface(41        [mic_transcribe,42         file_transcribe],43        ["Transcribe Microphone",44         "Transcribe Audio File"])45 46demo.launch(share=True)