File size: 894 Bytes
52a4fb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# Load the Automatic Speech Recognition pipeline from Hugging Face
asr = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")

def transcribe(audio):
    if audio is None:
        return "Please record or upload an audio file."
    # audio is a tuple: (sample_rate, numpy array)
    result = asr(audio)["text"]
    return result

description = """
# Speech-to-Text Converter
Record your voice or upload an audio file and get the transcription using Hugging Face's Whisper model.
"""

demo = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(source="microphone", type="numpy", label="Record or Upload Audio"),
    outputs=gr.Textbox(label="Transcribed Text"),
    title="Speech to Text App",
    description=description,
    allow_flagging="never",
    theme="default"
)

if __name__ == "__main__":
    demo.launch()