From a7c92b486e99c9abe51e56be22915d6ae96d7fba Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Mon, 11 Nov 2024 15:22:24 +0000 Subject: [PATCH] fix: drop lingua-franca (#47) --- __init__.py | 37 ++++++++++++++++++++----------------- requirements.txt | 2 ++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/__init__.py b/__init__.py index 0be194a..80a7c89 100644 --- a/__init__.py +++ b/__init__.py @@ -1,7 +1,7 @@ -# TODO classifiers > 0.0.8; check if normalize is still needed -from lingua_franca.parse import normalize, extract_number +from ovos_number_parser import extract_number from ovos_utils import classproperty from ovos_utils.process_utils import RuntimeRequirements +from ovos_utterance_normalizer import UtteranceNormalizerPlugin from ovos_workshop.decorators import intent_handler from ovos_workshop.intents import IntentBuilder from ovos_workshop.skills import OVOSSkill @@ -10,13 +10,6 @@ MAX_VOLUME = 100 -def amount_validator(response): - amount = extract_number(normalize(response)) - if amount: - return MIN_VOLUME <= amount <= MAX_VOLUME - return None - - class VolumeSkill(OVOSSkill): @classproperty def runtime_requirements(self): @@ -41,12 +34,22 @@ def _query_volume(self, message): # intents @intent_handler(IntentBuilder("change_volume").require("change").require("volume")) def handle_change_volume_intent(self, message): - volume_change = extract_number(normalize(message.data["utterance"])) + normalizer = UtteranceNormalizerPlugin.get_normalizer(self.lang) + utt = normalizer.normalize(message.data["utterance"]) + volume_change = extract_number(utt, lang=self.lang) if not volume_change: + + def amount_validator(response): + response = normalizer.normalize(response) + amount = extract_number(response, lang=self.lang) + if amount: + return MIN_VOLUME <= amount <= MAX_VOLUME + return None + response = self.get_response( "volume.change.amount", validator=amount_validator ) - volume_change = extract_number(normalize(response)) + volume_change = extract_number(normalizer.normalize(response), lang=self.lang) if volume_change >= 100: self.speak_dialog("volume.max") else: @@ -59,8 +62,10 @@ def handle_change_volume_intent(self, message): IntentBuilder("less_volume").require("quieter").require("volume") ) def handle_less_volume_intent(self, message): + normalizer = UtteranceNormalizerPlugin.get_normalizer(self.lang) + utt = normalizer.normalize(message.data["utterance"]) volume = self._query_volume(message) - volume_change = extract_number(normalize(message.data["utterance"])) or 10 + volume_change = extract_number(utt, lang=self.lang) or 10 self.bus.emit( message.forward("mycroft.volume.decrease", {"percent": volume_change / 100}) ) @@ -74,8 +79,10 @@ def handle_less_volume_intent(self, message): ) def handle_increase_volume_intent(self, message): volume = self._query_volume(message) + normalizer = UtteranceNormalizerPlugin.get_normalizer(self.lang) + utt = normalizer.normalize(message.data["utterance"]) if not (volume == MAX_VOLUME): - volume_change = extract_number(normalize(message.data["utterance"])) or 10 + volume_change = extract_number(utt, lang=self.lang) or 10 self.bus.emit( message.forward( "mycroft.volume.increase", {"percent": volume_change / 100} @@ -123,7 +130,3 @@ def handle_toggle_unmute_intent(self, message): def handle_query_volume(self, message): volume = self._query_volume(message) self.speak_dialog("volume.current", data={"volume": volume}) - - -def create_skill(): - return VolumeSkill() diff --git a/requirements.txt b/requirements.txt index 97a694d..76ac902 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ ovos-utils>=0.0.38,<1.0.0 ovos_workshop>=0.0.15,<3.0.0 +ovos-utterance-normalizer>=0.0.1,<1.0.0 +ovos-number-parser>=0.0.1,<1.0.0 \ No newline at end of file