bichnhan2701 commited on
Commit
e0ebe32
·
1 Parent(s): a97a315
Files changed (1) hide show
  1. app/core/asr_engine.py +22 -11
app/core/asr_engine.py CHANGED
@@ -81,7 +81,6 @@ def transcribe_file_chunks(
81
  """
82
  if not wav_path:
83
  return []
84
-
85
  out = model(
86
  wav_path,
87
  chunk_length_s=chunk_length_s,
@@ -89,24 +88,36 @@ def transcribe_file_chunks(
89
  return_timestamps=True,
90
  )
91
 
 
 
 
 
 
 
92
  chunks = []
93
- for c in out.get("chunks", []) or []:
94
- ts = c.get("timestamp") or [None, None]
95
- start, end = ts if len(ts) == 2 else (None, None)
 
 
 
 
 
 
 
96
 
97
  text = (c.get("text") or "").strip()
98
  if not text:
99
  continue
100
 
 
101
  if start is None or end is None:
102
  continue
103
 
104
- chunks.append(
105
- {
106
- "start": float(start),
107
- "end": float(end),
108
- "text": text,
109
- }
110
- )
111
 
112
  return chunks
 
81
  """
82
  if not wav_path:
83
  return []
 
84
  out = model(
85
  wav_path,
86
  chunk_length_s=chunk_length_s,
 
88
  return_timestamps=True,
89
  )
90
 
91
+ # Pipeline output can vary across transformers versions/models:
92
+ # - some return `chunks` (with `timestamp` list),
93
+ # - others return `segments` (with `start`/`end`),
94
+ # so be permissive and handle both shapes.
95
+ raw_segments = out.get("chunks") or out.get("segments") or []
96
+
97
  chunks = []
98
+ for c in raw_segments:
99
+ # try multiple timestamp shapes
100
+ start = None
101
+ end = None
102
+
103
+ if isinstance(c.get("timestamp"), (list, tuple)) and len(c.get("timestamp")) >= 2:
104
+ ts = c.get("timestamp")
105
+ start, end = ts[0], ts[1]
106
+ elif c.get("start") is not None and c.get("end") is not None:
107
+ start, end = c.get("start"), c.get("end")
108
 
109
  text = (c.get("text") or "").strip()
110
  if not text:
111
  continue
112
 
113
+ # If timestamps are missing, skip (we don't want chunks without timing)
114
  if start is None or end is None:
115
  continue
116
 
117
+ try:
118
+ chunks.append({"start": float(start), "end": float(end), "text": text})
119
+ except Exception:
120
+ # be robust against unexpected types
121
+ continue
 
 
122
 
123
  return chunks