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()