refactor funasr model. (#36108)

Signed-off-by: zixiao <shunli.dsl@alibaba-inc.com>
Co-authored-by: zixiao <shunli.dsl@alibaba-inc.com>
Co-authored-by: Isotr0py <mozf@mail2.sysu.edu.cn>
This commit is contained in:
AllenDou
2026-03-05 08:07:37 -08:00
committed by GitHub
co-authored by zixiao Isotr0py
parent 7196348157
commit 3ee68590c7
3 changed files with 24 additions and 57 deletions
@@ -370,7 +370,7 @@ class FunASRFeatureExtractor(SequenceFeatureExtractor):
)
olens = 1 + (speech_lengths - 3 + 2 * 1) // 2
olens = 1 + (olens - 3 + 2 * 1) // 2
fake_token_len = (olens - 1) // 2 + 1
fake_token_lengths = (olens - 1) // 2 + 1
if isinstance(input_features[0], list):
padded_inputs["input_features"] = [
np.asarray(feature, dtype=np.float32) for feature in input_features
@@ -382,8 +382,10 @@ class FunASRFeatureExtractor(SequenceFeatureExtractor):
if return_tensors is not None:
padded_inputs = padded_inputs.convert_to_tensors(return_tensors)
fake_token_lengths = torch.clamp(fake_token_lengths, min=1)
padded_inputs["speech_lengths"] = speech_lengths
padded_inputs["fake_token_len"] = fake_token_len
padded_inputs["fake_token_lengths"] = fake_token_lengths
return padded_inputs
@@ -471,7 +473,7 @@ class FunASRProcessor(ProcessorMixin):
for sample in text:
replace_str = []
while self.audio_token in sample:
num_audio_tokens = inputs["fake_token_len"].item()
num_audio_tokens = inputs["fake_token_lengths"].item()
expanded_audio_token = self.audio_token * num_audio_tokens