File size: 1,258 Bytes
41f01e4
 
 
 
f112b10
6bc8587
41f01e4
f112b10
ac7c9e3
 
41f01e4
ac7c9e3
 
 
41f01e4
f112b10
ac7c9e3
 
 
41f01e4
ac7c9e3
41f01e4
f112b10
ac7c9e3
 
f112b10
 
 
 
41f01e4
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
31
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()