Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,23 +13,37 @@ pipe = pipeline(
|
|
| 13 |
|
| 14 |
def transcribe(audio):
|
| 15 |
"""Transcribes Tamil speech from an audio file."""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
iface = gr.Interface(
|
| 35 |
fn=transcribe,
|
|
|
|
| 13 |
|
| 14 |
def transcribe(audio):
|
| 15 |
"""Transcribes Tamil speech from an audio file."""
|
| 16 |
+
try:
|
| 17 |
+
if audio is None:
|
| 18 |
+
return "Please record or upload an audio file."
|
| 19 |
+
|
| 20 |
+
print(f"[DEBUG] Received audio: {audio}")
|
| 21 |
+
|
| 22 |
+
# Handle filepath case from Gradio
|
| 23 |
+
audio_path = audio if isinstance(audio, str) else audio.get("name", None)
|
| 24 |
+
if audio_path is None:
|
| 25 |
+
return "Could not read audio file."
|
| 26 |
+
|
| 27 |
+
print(f"[DEBUG] Reading audio file: {audio_path}")
|
| 28 |
+
audio_data, sample_rate = sf.read(audio_path)
|
| 29 |
+
|
| 30 |
+
print(f"[DEBUG] Audio sample rate: {sample_rate}, shape: {audio_data.shape}")
|
| 31 |
+
|
| 32 |
+
transcription = pipe(
|
| 33 |
+
{"array": audio_data, "sampling_rate": sample_rate},
|
| 34 |
+
chunk_length_s=30,
|
| 35 |
+
batch_size=8,
|
| 36 |
+
return_timestamps=True,
|
| 37 |
+
)["text"]
|
| 38 |
+
|
| 39 |
+
print(f"[DEBUG] Transcription: {transcription}")
|
| 40 |
+
return transcription
|
| 41 |
+
|
| 42 |
+
except Exception as e:
|
| 43 |
+
import traceback
|
| 44 |
+
print("[ERROR] Exception during transcription:")
|
| 45 |
+
traceback.print_exc()
|
| 46 |
+
return f"Error: {str(e)}"
|
| 47 |
|
| 48 |
iface = gr.Interface(
|
| 49 |
fn=transcribe,
|