bichnhan2701 commited on
Commit
4cbfd1f
·
1 Parent(s): d6ff044
Files changed (1) hide show
  1. app/core/asr_engine.py +34 -19
app/core/asr_engine.py CHANGED
@@ -138,25 +138,40 @@ def transcribe_long_audio(
138
  combined_text_parts.append(part_text)
139
 
140
  raw_segs = out.get("chunks") or out.get("segments") or []
141
- for s in raw_segs:
142
- start = None
143
- end = None
144
- if isinstance(s.get("timestamp"), (list, tuple)) and len(s.get("timestamp")) >= 2:
145
- ts = s.get("timestamp")
146
- start, end = ts[0], ts[1]
147
- elif s.get("start") is not None and s.get("end") is not None:
148
- start, end = s.get("start"), s.get("end")
149
-
150
- text = (s.get("text") or "").strip()
151
- if not text or start is None or end is None:
152
- continue
153
-
154
- try:
155
- combined_chunks.append(
156
- {"start": float(start) + base_offset, "end": float(end) + base_offset, "text": text}
157
- )
158
- except Exception:
159
- continue
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  finally:
162
  for p in chunk_paths:
 
138
  combined_text_parts.append(part_text)
139
 
140
  raw_segs = out.get("chunks") or out.get("segments") or []
141
+ if raw_segs:
142
+ for s in raw_segs:
143
+ start = None
144
+ end = None
145
+ if isinstance(s.get("timestamp"), (list, tuple)) and len(s.get("timestamp")) >= 2:
146
+ ts = s.get("timestamp")
147
+ start, end = ts[0], ts[1]
148
+ elif s.get("start") is not None and s.get("end") is not None:
149
+ start, end = s.get("start"), s.get("end")
150
+
151
+ text = (s.get("text") or "").strip()
152
+ if not text or start is None or end is None:
153
+ continue
154
+
155
+ try:
156
+ combined_chunks.append(
157
+ {"start": float(start) + base_offset, "end": float(end) + base_offset, "text": text}
158
+ )
159
+ except Exception:
160
+ continue
161
+ else:
162
+ # If model returned text but no timestamped segments for this chunk,
163
+ # create a fallback chunk spanning the chunk file duration.
164
+ if part_text:
165
+ try:
166
+ cinfo = get_audio_info(cp) or {}
167
+ cdur = cinfo.get("duration") or chunk_length_s
168
+ combined_chunks.append({
169
+ "start": float(base_offset),
170
+ "end": float(base_offset) + float(cdur),
171
+ "text": part_text,
172
+ })
173
+ except Exception:
174
+ logger.exception("failed to create fallback chunk for %s", cp)
175
 
176
  finally:
177
  for p in chunk_paths: