File size: 842 Bytes
b15b0c6
73570fe
b15b0c6
73570fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# Load the Whisper model for speech recognition
pipe = pipeline("automatic-speech-recognition", model="openai/whisper-small")

# Function to handle the speech recognition
def transcribe_audio(audio):
    # Use the pipeline to transcribe the audio
    result = pipe(audio)["text"]
    return result

# Create a Gradio interface for the audio input and transcription output
interface = gr.Interface(
    fn=transcribe_audio,  # Function that handles the transcription
    inputs=gr.Audio(source="microphone", type="filepath"),  # Input as audio from mic
    outputs="text",  # Output as text
    title="Whisper Speech Recognition",
    description="Transcribe speech to text using OpenAI's Whisper model."
)

# Launch the Gradio interface
if __name__ == "__main__":
    interface.launch()