File size: 737 Bytes
2b271d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py

import gradio as gr
import torch
from transformers import pipeline

# Load a fast automatic speech recognition pipeline
asr_pipeline = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")

def transcribe_audio(audio):
    if audio is None:
        return "No audio input"
    
    text = asr_pipeline(audio)["text"]
    return text

# Gradio Interface
iface = gr.Interface(
    fn=transcribe_audio,
    inputs=gr.Audio(sources=["microphone"], type="filepath"),
    outputs=gr.Textbox(label="Recognized Text"),
    live=True,
    title="Real-time Voice to Text (Fast Version)",
    description="Speak into your microphone and get instant transcription!",
)

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