Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def __call__(self, audio_in: np.ndarray, **kwargs):
asr_res = []

if waveforms.shape[1] < 16 * 60 and is_final and len(cache) > 0:
# extract_feat is skipped here, so reset the frontend as its final call would.
self.frontend.cache_reset()
cache["last_chunk"] = True
feats = cache["feats"]
feats_len = np.array([feats.shape[1]]).astype(np.int32)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_funasr_onnx_paraformer_online_empty_final.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ def test_short_final_does_not_contaminate_next_stream(self):
reference(np.zeros(960, np.float32), param_dict={"cache": {}})
np.testing.assert_array_equal(model.infer.call_args.args[0], reference.infer.call_args.args[0])

def test_short_final_after_features_does_not_contaminate_next_stream(self):
audio = (0.1 * np.sin(np.arange(10560) * 2 * np.pi * 440 / 16000)).astype(np.float32)
next_audio = (0.05 * np.sin(np.arange(9600) * 2 * np.pi * 800 / 16000)).astype(np.float32)
reference = self.make_model()
reference(next_audio, param_dict={"cache": {}})
for samples in (0, 1, 500, 959, 960):
with self.subTest(samples=samples):
model = self.make_model()
cache = {}
model(audio[:9600], param_dict={"cache": cache})
model(audio[9600 : 9600 + samples], param_dict={"cache": cache, "is_final": True})
self.assertTrue(cache["last_chunk"])
model(next_audio, param_dict={"cache": {}})
np.testing.assert_array_equal(
model.infer.call_args.args[0], reference.infer.call_args.args[0]
)

def test_empty_nonfinal_call_preserves_existing_cache(self):
model = self.make_model()
cache = {}
Expand Down
Loading