Splice frames

Concatenate each frame with its left/right context neighbors — the equivalent of kaldi's splice-feats (kaldi-native-fbank/csrc/feature-splice.h, SpliceFrames).

Edge frames are replicated (out-of-range indices clamp to the first/last frame), so the output keeps the same number of frames and has dim * (1 + left + right) dimensions.

import kaldi_native_fbank as knf

opts = knf.SpliceOptions(left_context=3, right_context=3)
spliced = knf.splice_frames(feats, opts)  # (T, 7 * dim)

API reference

class kaldi_native_fbank.SpliceOptions(self: kaldi_native_fbank.SpliceOptions, left_context: SupportsInt = 3, right_context: SupportsInt = 3)

Options for splice_frames().

Mirrors the flags of kaldi's splice-feats.

See also

splice_frames()

Construct with the given contexts.

All fields are optional keyword arguments; the defaults are shown in the signature.

Parameters:
  • left_context -- Number of preceding frames to append (kaldi splice-feats --left-context).

  • right_context -- Number of following frames to append (kaldi splice-feats --right-context).

__init__(self: kaldi_native_fbank.SpliceOptions, left_context: SupportsInt = 3, right_context: SupportsInt = 3) → None

Construct with the given contexts.

All fields are optional keyword arguments; the defaults are shown in the signature.

Parameters:
  • left_context -- Number of preceding frames to append (kaldi splice-feats --left-context).

  • right_context -- Number of following frames to append (kaldi splice-feats --right-context).

property left_context

Number of preceding frames to append.

Same as kaldi splice-feats --left-context.

property right_context

Number of following frames to append.

Same as kaldi splice-feats --right-context.

kaldi_native_fbank.splice_frames(feats: typing.Annotated[numpy.typing.ArrayLike, numpy.float32, "[m, n]"], opts: kaldi_native_fbank.SpliceOptions = <kaldi_native_fbank.SpliceOptions object at 0x76bdc1e6a0b0>) → Annotated[numpy.typing.NDArray[numpy.float32], '[m, n]']

Splice each frame with its left/right context neighbors.

This is kaldi's splice-feats (same arithmetic): for every frame index \(t\) the output row is

\[y_t = [ x_{\max(0, t-L)}, \ldots, x_{\min(T-1, t+R)} ]\]

where \(L\) is opts.left_context, \(R\) is opts.right_context and \(T\) is the number of input frames. Edge frames are replicated: out-of-range indices clamp to the first/last frame. The output therefore has the same number of frames as the input and dim * (1 + L + R) dimensions.

Parameters:
  • feats (numpy.ndarray) -- Feature matrix of shape (num_frames, dim), float32.

  • opts -- Contexts; see SpliceOptions.

Returns:

The spliced matrix of shape (num_frames, dim * (1 + L + R)), float32.

Return type:

numpy.ndarray

Example

opts = knf.SpliceOptions(left_context=3, right_context=3)
spliced = knf.splice_frames(feats, opts)  # (T, 7 * dim)

See also

SpliceOptions