1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// transcribe-kaldi-fbank.h - kaldi-style HTK mel fbank + LFR stack
// + optional per-feature CMVN, host-side, single-utterance.
//
// Pure host code (no ggml). Mirrors `torchaudio.compliance.kaldi.fbank`
// with the parameters FunASR's WavFrontend passes (window=hamming,
// dither=0, energy_floor=0, snip_edges=True, num_mel_bins=80,
// frame_length=25ms, frame_shift=10ms), plus FunASR's LFR stack and the
// optional per-feature CMVN. Used by `arch/sensevoice` (apply_cmvn=true)
// and `arch/funasr_nano` (apply_cmvn=false).
//
// Key behaviors:
// * Hamming window (kaldi's symmetric "hamming": 0.54 - 0.46·cos(2πn/(N-1))).
// * Per-frame preemphasis coefficient 0.97 with kaldi's special
// boundary `x[0] = x[0] * (1 - 0.97)`.
// * Per-frame DC offset removal before preemph.
// * Sample upscale ×32768 before framing when `upscale_samples=true`
// (WavFrontend treats audio as int16 magnitude in float storage).
// * snip_edges=True: drop trailing partial frames.
// * HTK mel filterbank (triangular bins peak=1, no area
// normalization), low_freq=20 Hz, high_freq=Nyquist.
// * round_to_power_of_two=True: per-frame FFT size = next_pow2(win_length).
// * Low-frame-rate stack (m, n): output frame i is the concatenation
// of input frames [n·i .. n·i + m), with kaldi-style centered left
// padding ((m-1)/2 copies of frame 0) and right-edge clamping.
// * Per-feature CMVN: (x + shift) * scale, applied after LFR. Shift
// and scale are length d_input.
//
// The frontend is built once at load time (window + mel filterbank
// cached) and run once per transcribe_run. Construction is `O(n_mels ·
// padded_n_fft)`; compute is `O(T · n_mels · padded_n_fft)`.
namespace transcribe // namespace transcribe