import json, sys
import numpy as np
from faster_whisper import WhisperModel
m = WhisperModel("small", device="cpu", compute_type="int8", cpu_threads=4)
segs, info = m.transcribe(np.fromfile("ref16k.f32", dtype=np.float32), language="zh", beam_size=5, vad_filter=True, initial_prompt="以下是繁體中文的課程講解,夾雜英文單字。")
out = [dict(start=s.start, end=s.end, text=s.text.strip()) for s in segs]
json.dump(out, open("ref-segments.json", "w"), ensure_ascii=False, indent=1)
print(len(out), "segments, duration", info.duration)
