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
+13 -3
View File
@@ -27,6 +27,16 @@ SWIFT_POSE_ALT = os.path.join(
SWIFT_POSE_PROGRESS_RE = re.compile(r"\[SwiftPose\] 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_pose(
video_path: str,
output_path: str,
@@ -67,7 +77,7 @@ def process_pose(
# Write interpolated output
with open(output_path, 'w') as f:
json.dump(interpolated_data, f)
json.dump(round_json_numbers(interpolated_data), f)
# Delete .json.tmp file so executor.rs won't restore it
if os.path.exists(tmp_path):
@@ -294,7 +304,7 @@ def _fallback(video_path, output_path, uuid, sample_interval):
if len(frames) == 0:
result["status"] = "no_face"
with open(output_path, "w") as f:
json.dump(result, f, indent=2)
json.dump(round_json_numbers(result), f, indent=2)
return result
@@ -320,7 +330,7 @@ if __name__ == "__main__":
result = process_pose(args.video_path, args.output_path, args.uuid,
args.sample_interval, publisher, target_frames)
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"Pose: {len(result.get('frames', []))} frames with poses")
if publisher:
publisher.complete("pose", f"{len(result.get('frames',[]))} frames")