File size: 1,000 Bytes
90c365c a11d16f 404555b 9171b87 a11d16f 90c365c 9171b87 90c365c 6a4ac4f bee789d 90c365c |
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 torch
from transformers import pipeline
import gradio as gr
# Initialize the speech recognition pipeline
pipe = pipeline(
"automatic-speech-recognition",
model="openai/whisper-small",
chunk_length_s=30,
device=-1
)
# Function to transcribe audio using the OpenAI Whisper model
def transcript_audio(audio_file):
# Transcribe the audio file and return the result
result = pipe(audio_file, batch_size=8)["text"]
return result
# Set up Gradio interface
audio_input = gr.Audio(sources="upload", type="filepath") # Audio input
output_text = gr.Textbox() # Text output
# Create the Gradio interface with the function, inputs, and outputs
iface = gr.Interface(fn=transcript_audio,
inputs=audio_input, outputs=output_text,
title="Audio Transcription",
description="This is a simple web app for audio transcription (English-only) using Whisper model from OpenAI.")
# Launch the Gradio app
iface.launch() |