leenag commited on
Commit
c838225
·
verified ·
1 Parent(s): 549199f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -17
app.py CHANGED
@@ -13,23 +13,37 @@ pipe = pipeline(
13
 
14
  def transcribe(audio):
15
  """Transcribes Tamil speech from an audio file."""
16
- if audio is None:
17
- return "Please record or upload an audio file."
18
-
19
- # Make sure to handle audio path properly
20
- audio_path = audio if isinstance(audio, str) else audio.get("name", None)
21
- if audio_path is None:
22
- return "Could not read audio file."
23
-
24
- audio_data, sample_rate = sf.read(audio_path)
25
- transcription = pipe(
26
- {"array": audio_data, "sampling_rate": sample_rate},
27
- chunk_length_s=30,
28
- batch_size=8,
29
- return_timestamps=True,
30
- )["text"]
31
-
32
- return transcription
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,