王梦迪
2025-05-26 9038340be707aa7cbf62fcbf33ab615bb266abdb
runtime/python/onnxruntime/funasr_onnx/utils/frontend.py
@@ -2,6 +2,7 @@
from pathlib import Path
from typing import Any, Dict, Iterable, List, NamedTuple, Set, Tuple, Union
import copy
from functools import lru_cache
import numpy as np
import kaldi_native_fbank as knf
@@ -45,7 +46,7 @@
        self.cmvn_file = cmvn_file
        if self.cmvn_file:
            self.cmvn = self.load_cmvn()
            self.cmvn = load_cmvn(self.cmvn_file)
        self.fbank_fn = None
        self.fbank_beg_idx = 0
        self.reset_status()
@@ -122,12 +123,26 @@
        inputs = (inputs + means) * vars
        return inputs
    def load_cmvn(
        self,
    ) -> np.ndarray:
        with open(self.cmvn_file, "r", encoding="utf-8") as f:
            lines = f.readlines()
@lru_cache()
def load_cmvn(cmvn_file: Union[str, Path]) -> np.ndarray:
    """load cmvn file to numpy array.
    Args:
        cmvn_file (Union[str, Path]): cmvn file path.
    Raises:
        FileNotFoundError: cmvn file not exits.
    Returns:
        np.ndarray: cmvn array. shape is (2, dim).The first row is means, the second row is vars.
    """
    cmvn_file = Path(cmvn_file)
    if not cmvn_file.exists():
        raise FileNotFoundError("cmvn file not exits")
    with open(cmvn_file, "r", encoding="utf-8") as f:
        lines = f.readlines()
        means_list = []
        vars_list = []
        for i in range(len(lines)):