Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
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()
|