gautamthulasiraman's picture
Update app.py
6bc8587 verified
import gradio as gr
from pydub import AudioSegment
from faster_whisper import WhisperModel
# βœ… Correct model for faster-whisper (not OpenAI's)
model = WhisperModel("guillaumekln/faster-whisper-large-v2", compute_type="int8")
# πŸ”„ Convert to 16kHz mono WAV for whisper
def convert_to_wav(input_path):
audio = AudioSegment.from_file(input_path)
audio = audio.set_frame_rate(16000).set_channels(1).set_sample_width(2)
output_path = input_path.replace(".", "_ready.")
audio.export(output_path, format="wav")
return output_path
# 🧠 Transcribe and detect language
def transcribe_and_detect_lang(file_path):
wav_path = convert_to_wav(file_path)
segments, info = model.transcribe(wav_path)
transcript = "\n".join([seg.text for seg in segments])
return f"🌐 Detected Language: {info.language}\n\nπŸ“ Transcript:\n{transcript}"
# πŸš€ UI with Gradio
gr.Interface(
fn=transcribe_and_detect_lang,
inputs=gr.Audio(type="filepath", label="🎧 Upload Audio"),
outputs=gr.Textbox(label="πŸ“‹ Transcript + Language"),
title="🌍 Language Identifier with Whisper",
description="Upload any audio file (English, Tamil, Hindi, etc.), and this app detects the language and gives the transcript.",
).launch()