|
import gradio as gr |
|
from pydub import AudioSegment |
|
from faster_whisper import WhisperModel |
|
|
|
|
|
model = WhisperModel("guillaumekln/faster-whisper-large-v2", compute_type="int8") |
|
|
|
|
|
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 |
|
|
|
|
|
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}" |
|
|
|
|
|
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() |
|
|