gautamthulasiraman commited on
Commit
ac7c9e3
Β·
verified Β·
1 Parent(s): a84ec0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -3,24 +3,26 @@ from pydub import AudioSegment
3
  from faster_whisper import WhisperModel
4
  import os
5
 
 
6
  model = WhisperModel("openai/whisper-large-v3-turbo", compute_type="int8")
7
 
8
- def convert_to_wav(file_path):
9
- audio = AudioSegment.from_file(file_path)
10
  audio = audio.set_frame_rate(16000).set_channels(1).set_sample_width(2)
11
- out_path = file_path.replace(".", "_ready.")
12
- audio.export(out_path, format="wav")
13
- return out_path
14
 
15
- def detect_language(audio_file):
16
- wav = convert_to_wav(audio_file.name)
17
- segments, info = model.transcribe(wav)
18
  transcript = "\n".join([seg.text for seg in segments])
19
- return f"🌐 Language: {info.language}\n\nπŸ“ Transcript:\n{transcript}"
20
 
21
- gr.Interface(fn=detect_language,
22
- inputs=gr.Audio(type="filepath"),
23
- outputs="text",
24
- title="🎧 Audio Language Detector",
25
- description="Drop any MP3/WAV/FLAC to identify spoken language & get transcript."
 
26
  ).launch()
 
3
  from faster_whisper import WhisperModel
4
  import os
5
 
6
+ # Load model from Hugging Face (it will download & cache automatically)
7
  model = WhisperModel("openai/whisper-large-v3-turbo", compute_type="int8")
8
 
9
+ def convert_to_wav(input_path):
10
+ audio = AudioSegment.from_file(input_path)
11
  audio = audio.set_frame_rate(16000).set_channels(1).set_sample_width(2)
12
+ output_path = input_path.replace(".", "_ready.")
13
+ audio.export(output_path, format="wav")
14
+ return output_path
15
 
16
+ def transcribe_and_detect_lang(file_path):
17
+ wav_path = convert_to_wav(file_path)
18
+ segments, info = model.transcribe(wav_path)
19
  transcript = "\n".join([seg.text for seg in segments])
20
+ return f"🌐 Detected Language: {info.language}\n\nπŸ“ Transcript:\n{transcript}"
21
 
22
+ gr.Interface(
23
+ fn=transcribe_and_detect_lang,
24
+ inputs=gr.Audio(type="filepath", label="🎧 Upload Audio File"),
25
+ outputs=gr.Textbox(label="πŸ“‹ Output"),
26
+ title="🌍 Whisper Language Identifier",
27
+ description="Upload an audio file in any language (Tamil, Hindi, English, etc.) and detect its language + get transcription."
28
  ).launch()