gepard-onnx / scripts /transcribe2.py
matthiastl's picture
gepard-1.0 for CPUs (ONNX)
2d4936d
Raw History Blame Contribute Delete
964 Bytes
"""Repeatable transcription: temperature 0, no fallback, no context carried over."""
import sys, json; from pathlib import Path
import numpy as np
from scipy.io import wavfile
from scipy.signal import resample_poly
from faster_whisper import WhisperModel
m = WhisperModel("Systran/faster-whisper-small", device="cpu", compute_type="int8", local_files_only=True)
for d in sys.argv[1:]:
out = {}
for f in sorted(Path(d).glob("*.wav")):
rate, x = wavfile.read(f); x = x.astype(np.float32) / (32768 if x.dtype == np.int16 else 1); y = resample_poly(x, 320, 441).astype(np.float32)
s, _ = m.transcribe(y, language="en", beam_size=5, temperature=0.0, condition_on_previous_text=False, compression_ratio_threshold=None, log_prob_threshold=None, no_speech_threshold=None, vad_filter=False)
out[f.stem] = " ".join(p.text.strip() for p in s)
json.dump(out, open(Path(d) / "text.json", "w")); print(d, len(out), "transcribed", flush=True)