from agr_assistent.audio.wakeword import ( WakeWordMatcher, contains_phrase, normalize_phrase, ) def test_normalize_phrase() -> None: assert normalize_phrase(" Эй, Ассистент ") == ("эй", "ассистент") def test_contains_phrase_matches_whole_words_in_order() -> None: words = "слушай эй ассистент включи".split() assert contains_phrase(words, ("эй", "ассистент")) assert not contains_phrase(words, ("ассистент", "эй")) assert not contains_phrase("ассистентка пришла".split(), ("ассистент",)) def test_partial_hypothesis_must_hold_for_several_updates() -> None: matcher = WakeWordMatcher([("ассистент",)], required_streak=2) assert not matcher.update_partial("ассистент") assert not matcher.update_partial("ассистентка") # гипотеза исправилась — счёт сброшен assert not matcher.update_partial("ассистентка ассистент") assert matcher.update_partial("ассистентка ассистент какая") def test_final_result_matches_immediately() -> None: matcher = WakeWordMatcher([("эй", "ассистент")], required_streak=3) assert matcher.update_final("ну эй ассистент") assert not matcher.update_final("просто ассистент")