fix: ASRX fallback to ASR segments on error instead of silent_audio
When ASRX processing fails (error or exception), it now falls back to ASR segments instead of returning silent_audio with 0 segments. This ensures asrx_segments >= asr_segments always, fixing the bug where ASRX would report 0 segments even when ASR detected speech.
This commit is contained in:
@@ -228,10 +228,21 @@ def process_asrx(video_path: str, output_path: str, uuid: str = "",
|
|||||||
if "error" in result:
|
if "error" in result:
|
||||||
if publisher:
|
if publisher:
|
||||||
publisher.error("asrx", result["error"])
|
publisher.error("asrx", result["error"])
|
||||||
output_result = {"status": "silent_audio", "language": None, "segments": [], "segment_count": 0}
|
# Fallback to ASR segments if ASRX fails but ASR has content
|
||||||
|
if asr_segments:
|
||||||
|
print(f"[ASRX] Resume error, falling back to {len(asr_segments)} ASR segments", file=sys.stderr)
|
||||||
|
output_result = {
|
||||||
|
"status": "has_transcript",
|
||||||
|
"language": None,
|
||||||
|
"segments": [{"start_time": s["start"], "end_time": s["end"], "text": s["text"], "speaker_id": "SPEAKER_0"} for s in asr_segments],
|
||||||
|
"segment_count": len(asr_segments),
|
||||||
|
"fallback_from_asr": True,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
output_result = {"status": "silent_audio", "language": None, "segments": [], "segment_count": 0}
|
||||||
_atomic_write(output_path, output_result)
|
_atomic_write(output_path, output_result)
|
||||||
if publisher:
|
if publisher:
|
||||||
publisher.complete("asrx", "0 segments")
|
publisher.complete("asrx", f"{output_result['segment_count']} segments")
|
||||||
_cleanup(tmp_dir)
|
_cleanup(tmp_dir)
|
||||||
return output_result
|
return output_result
|
||||||
|
|
||||||
@@ -264,10 +275,21 @@ def process_asrx(video_path: str, output_path: str, uuid: str = "",
|
|||||||
publisher.error("asrx", str(e))
|
publisher.error("asrx", str(e))
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
output_result = {"status": "silent_audio", "language": None, "segments": [], "segment_count": 0}
|
# Fallback to ASR segments if ASRX fails but ASR has content
|
||||||
|
if asr_segments:
|
||||||
|
print(f"[ASRX] Resume exception, falling back to {len(asr_segments)} ASR segments", file=sys.stderr)
|
||||||
|
output_result = {
|
||||||
|
"status": "has_transcript",
|
||||||
|
"language": None,
|
||||||
|
"segments": [{"start_time": s["start"], "end_time": s["end"], "text": s["text"], "speaker_id": "SPEAKER_0"} for s in asr_segments],
|
||||||
|
"segment_count": len(asr_segments),
|
||||||
|
"fallback_from_asr": True,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
output_result = {"status": "silent_audio", "language": None, "segments": [], "segment_count": 0}
|
||||||
_atomic_write(output_path, output_result)
|
_atomic_write(output_path, output_result)
|
||||||
if publisher:
|
if publisher:
|
||||||
publisher.complete("asrx", "0 segments")
|
publisher.complete("asrx", f"{output_result['segment_count']} segments")
|
||||||
_cleanup(tmp_dir)
|
_cleanup(tmp_dir)
|
||||||
return output_result
|
return output_result
|
||||||
|
|
||||||
@@ -328,10 +350,21 @@ def process_asrx(video_path: str, output_path: str, uuid: str = "",
|
|||||||
if "error" in result:
|
if "error" in result:
|
||||||
if publisher:
|
if publisher:
|
||||||
publisher.error("asrx", result["error"])
|
publisher.error("asrx", result["error"])
|
||||||
output_result = {"status": "silent_audio", "language": None, "segments": [], "segment_count": 0}
|
# Fallback to ASR segments if ASRX fails
|
||||||
|
if asr_segments:
|
||||||
|
print(f"[ASRX] ASRX failed, falling back to {len(asr_segments)} ASR segments", file=sys.stderr)
|
||||||
|
output_result = {
|
||||||
|
"status": "has_transcript",
|
||||||
|
"language": None,
|
||||||
|
"segments": [{"start_time": s["start"], "end_time": s["end"], "text": s["text"], "speaker_id": "SPEAKER_0"} for s in asr_segments],
|
||||||
|
"segment_count": len(asr_segments),
|
||||||
|
"fallback_from_asr": True,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
output_result = {"status": "silent_audio", "language": None, "segments": [], "segment_count": 0}
|
||||||
_atomic_write(output_path, output_result)
|
_atomic_write(output_path, output_result)
|
||||||
if publisher:
|
if publisher:
|
||||||
publisher.complete("asrx", "0 segments")
|
publisher.complete("asrx", f"{output_result['segment_count']} segments")
|
||||||
_cleanup(tmp_dir)
|
_cleanup(tmp_dir)
|
||||||
return output_result
|
return output_result
|
||||||
|
|
||||||
@@ -359,10 +392,21 @@ def process_asrx(video_path: str, output_path: str, uuid: str = "",
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
output_result = {"status": "silent_audio", "language": None, "segments": [], "segment_count": 0}
|
# Fallback to ASR segments if ASRX fails but ASR has content
|
||||||
|
if asr_segments:
|
||||||
|
print(f"[ASRX] Exception occurred, falling back to {len(asr_segments)} ASR segments", file=sys.stderr)
|
||||||
|
output_result = {
|
||||||
|
"status": "has_transcript",
|
||||||
|
"language": None,
|
||||||
|
"segments": [{"start_time": s["start"], "end_time": s["end"], "text": s["text"], "speaker_id": "SPEAKER_0"} for s in asr_segments],
|
||||||
|
"segment_count": len(asr_segments),
|
||||||
|
"fallback_from_asr": True,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
output_result = {"status": "silent_audio", "language": None, "segments": [], "segment_count": 0}
|
||||||
_atomic_write(output_path, output_result)
|
_atomic_write(output_path, output_result)
|
||||||
if publisher:
|
if publisher:
|
||||||
publisher.complete("asrx", "0 segments")
|
publisher.complete("asrx", f"{output_result['segment_count']} segments")
|
||||||
# 如果 checkpoint 已存在(Step 3 完成後 crash),保留 WAV 給 resume
|
# 如果 checkpoint 已存在(Step 3 完成後 crash),保留 WAV 給 resume
|
||||||
if not os.path.exists(checkpoint_path):
|
if not os.path.exists(checkpoint_path):
|
||||||
_cleanup(tmp_dir)
|
_cleanup(tmp_dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user