feat: round output JSON floats to 2dp + unify ensure_ascii for asr/asrx

This commit is contained in:
Accusys
2026-08-16 06:38:39 +08:00
parent 39e9ce4c3b
commit 5e6a7b7d51
18 changed files with 249 additions and 45 deletions
+12 -1
View File
@@ -27,6 +27,17 @@ SWIFT_OCR_ALT = os.path.join(
SWIFT_PROGRESS_RE = re.compile(r"\[SwiftOCR\] Progress:\s*(\d+)%")
def _round_json_numbers(obj):
"""Recursively round all float values to 2 decimal places (JSON output only)."""
if isinstance(obj, float):
return round(obj, 2)
if isinstance(obj, dict):
return {k: _round_json_numbers(v) for k, v in obj.items()}
if isinstance(obj, list):
return [_round_json_numbers(v) for v in obj]
return obj
def process_ocr(
video_path: str,
output_path: str,
@@ -121,7 +132,7 @@ if __name__ == "__main__":
publisher)
with open(args.output_path, "w") as f:
json.dump(result, f, indent=2)
json.dump(_round_json_numbers(result), f, indent=2)
print(f"OCR: {len(result.get('frames', []))} frames with text")
if publisher:
publisher.complete("ocr", f"{len(result.get('frames',[]))} frames")