#!/usr/bin/env python3
"""Convert whisper-cli JSON (-ml 1 -sow -oj) to a Scribe-like transcript:
{ "words": [ {start, end, text, type:"word"} ] }  (times in seconds)."""
import json
import sys

src, dst = sys.argv[1], sys.argv[2]
d = json.load(open(src))
words = []
for s in d.get("transcription", []):
    t = (s.get("text") or "").strip()
    o = s.get("offsets", {})
    if not t or o.get("from") is None:
        continue
    words.append({"start": o["from"] / 1000.0, "end": o["to"] / 1000.0, "text": t, "type": "word"})
json.dump({"words": words}, open(dst, "w"))
print(f"{dst}: {len(words)} words, {words[-1]['end']:.0f}s" if words else "no words")
