|
import gradio as gr |
|
from pydub import AudioSegment |
|
from faster_whisper import WhisperModel |
|
import os |
|
|
|
model = WhisperModel("openai/whisper-large-v3-turbo", compute_type="int8") |
|
|
|
def convert_to_wav(file_path): |
|
audio = AudioSegment.from_file(file_path) |
|
audio = audio.set_frame_rate(16000).set_channels(1).set_sample_width(2) |
|
out_path = file_path.replace(".", "_ready.") |
|
audio.export(out_path, format="wav") |
|
return out_path |
|
|
|
def detect_language(audio_file): |
|
wav = convert_to_wav(audio_file.name) |
|
segments, info = model.transcribe(wav) |
|
transcript = "\n".join([seg.text for seg in segments]) |
|
return f"π Language: {info.language}\n\nπ Transcript:\n{transcript}" |
|
|
|
gr.Interface(fn=detect_language, |
|
inputs=gr.Audio(type="filepath"), |
|
outputs="text", |
|
title="π§ Audio Language Detector", |
|
description="Drop any MP3/WAV/FLAC to identify spoken language & get transcript." |
|
).launch() |
|
|