From 89c64d1f03816f98831d70529a5c21373532df66 Mon Sep 17 00:00:00 2001
From: j1nx
Date: Wed, 16 Mar 2022 20:18:29 +0100
Subject: [PATCH] Test volume skill - phal migration
---
.../0001-integrate-with-PHAL.patch | 192 ++++++++++++++++++
1 file changed, 192 insertions(+)
create mode 100644 buildroot-external/package/mycroft-skill-ovos-volume/0001-integrate-with-PHAL.patch
diff --git a/buildroot-external/package/mycroft-skill-ovos-volume/0001-integrate-with-PHAL.patch b/buildroot-external/package/mycroft-skill-ovos-volume/0001-integrate-with-PHAL.patch
new file mode 100644
index 00000000..7da16b7e
--- /dev/null
+++ b/buildroot-external/package/mycroft-skill-ovos-volume/0001-integrate-with-PHAL.patch
@@ -0,0 +1,192 @@
+From 79c82a85765730f3c719faa74e1ffd74b63c56ae Mon Sep 17 00:00:00 2001
+From: jarbasai
+Date: Wed, 16 Mar 2022 15:03:33 +0000
+Subject: [PATCH] integrate with PHAL
+
+https://github.com/OpenVoiceOS/ovos-PHAL-plugin-alsa
+---
+ __init__.py | 125 +++++++++--------------------------------
+ blop-mark-diangelo.wav | Bin 87676 -> 0 bytes
+ 2 files changed, 27 insertions(+), 98 deletions(-)
+ delete mode 100644 blop-mark-diangelo.wav
+
+diff --git a/__init__.py b/__init__.py
+index e85793c..03bb87f 100644
+--- a/__init__.py
++++ b/__init__.py
+@@ -1,86 +1,18 @@
+-from os.path import dirname, join
+-
+ from adapt.intent import IntentBuilder
+ from mycroft.skills.core import MycroftSkill, intent_handler, intent_file_handler
+-from mycroft.util import play_wav, normalize
++from mycroft.util import normalize
+ from mycroft.util.parse import extract_number
+-from ovos_utils.sound.alsa import AlsaControl
+-from mycroft_bus_client import Message
+
+
+ class VolumeSkill(MycroftSkill):
+- def __init__(self):
+- super(VolumeSkill, self).__init__("VolumeSkill")
+- self.volume_sound = join(dirname(__file__), "blop-mark-diangelo.wav")
+-
+- # bus api
+- def initialize(self):
+- self.add_event("mycroft.volume.get", self.handle_volume_request)
+- self.add_event("mycroft.volume.set", self.handle_volume_change)
+- self.add_event("mycroft.volume.set.gui",
+- self.handle_volume_change_gui)
+- self.handle_volume_request(Message("mycroft.volume.get"))
+- self.add_event("mycroft.volume.mute",
+- self.handle_mute_intent)
+- self.add_event("mycroft.volume.unmute",
+- self.handle_unmute_intent)
+-
+- def handle_volume_request(self, message):
+- percent = self.get_volume() / 100
+- self.bus.emit(message.response({"percent": percent}))
+-
+- def handle_volume_change(self, message):
+- percent = message.data["percent"] * 100
+- self.set_volume(percent)
+-
+- def handle_volume_change_gui(self, message):
+- percent = message.data["percent"] * 100
+- self.set_volume(percent, set_by_gui=True)
+-
+- # volume control
+- def get_intro_message(self):
+- # just pretend this method is called "on_first_boot"
+- # will only run once when the skill is loaded for the first time
+- self.set_volume(50)
+-
+- def get_volume(self):
+- return AlsaControl().get_volume_percent()
+-
+- def set_volume(self, percent=None, set_by_gui=False):
+- volume = int(percent)
+- volume = min(100, volume)
+- volume = max(0, volume)
+- AlsaControl().set_volume_percent(volume)
+- play_wav(self.volume_sound)
+-
+- # report change to GUI
+- if not set_by_gui:
+- percent = volume / 100
+- self.handle_volume_request(
+- Message("mycroft.volume.get", {"percent": percent}))
+-
+- def increase_volume(self, volume_change=None):
+- if not volume_change:
+- volume_change = 15
+- AlsaControl().increase_volume(volume_change)
+- play_wav(self.volume_sound)
+- self.handle_volume_request(Message("mycroft.volume.get"))
+-
+- def decrease_volume(self, volume_change=None):
+- if not volume_change:
+- volume_change = -15
+- if volume_change > 0:
+- volume_change = 0 - volume_change
+- AlsaControl().increase_volume(volume_change)
+- play_wav(self.volume_sound)
+- self.handle_volume_request(Message("mycroft.volume.get"))
+
+ # intents
+ @intent_handler(IntentBuilder("change_volume").require('change_volume'))
+ def handle_change_volume_intent(self, message):
+ utterance = message.data['utterance']
+ volume_change = extract_number(normalize(utterance))
+- self.set_volume(volume_change)
++ self.bus.emit(message.forward("mycroft.volume.set",
++ {"percent": volume_change / 100}))
+ if volume_change >= 100:
+ self.speak_dialog('max.volume')
+ else:
+@@ -91,61 +23,58 @@ def handle_change_volume_intent(self, message):
+ def handle_less_volume_intent(self, message):
+ utterance = message.data['utterance']
+ volume_change = extract_number(normalize(utterance))
+- if volume_change > 0:
+- volume_change = 0 - volume_change
+- self.decrease_volume(volume_change)
++ self.bus.emit(message.forward("mycroft.volume.decrease",
++ {"percent": volume_change / 100}))
+
+- @intent_handler(
+- IntentBuilder("increase_volume").require('increase_volume'))
++ @intent_handler(IntentBuilder("increase_volume").require('increase_volume'))
+ def handle_increase_volume_intent(self, message):
+ utterance = message.data['utterance']
+ volume_change = extract_number(normalize(utterance))
+- self.increase_volume(volume_change)
++ self.bus.emit(message.forward("mycroft.volume.increase",
++ {"percent": volume_change / 100}))
+
+ @intent_file_handler('max_volume.intent')
+ def handle_max_volume_intent(self, message):
+- self.set_volume(100)
++ self.bus.emit(message.forward("mycroft.volume.set",
++ {"percent": 1.0}))
+ self.speak_dialog('max.volume')
+
+ @intent_file_handler('high_volume.intent')
+ def handle_high_volume_intent(self, message):
+- self.set_volume(85)
++ self.bus.emit(message.forward("mycroft.volume.set",
++ {"percent": 0.9}))
+
+ @intent_file_handler('default_volume.intent')
+- def handle_default_volume_ntent(self, message):
+- self.set_volume(70)
++ def handle_default_volume_intent(self, message):
++ self.bus.emit(message.forward("mycroft.volume.set",
++ {"percent": 0.7}))
+
+ @intent_file_handler('low_volume.intent')
+ def handle_low_volume_intent(self, message):
+- self.set_volume(30)
++ self.bus.emit(message.forward("mycroft.volume.set",
++ {"percent": 0.3}))
+
+ @intent_file_handler('mute.intent')
+ def handle_mute_intent(self, message):
+- self.log.info("User muted audio.")
+- AlsaControl().mute()
+- self.bus.emit(Message("mycroft.volume.get").response({"percent" : 0}))
++ self.bus.emit(message.forward("mycroft.volume.mute"))
+
+ @intent_file_handler('unmute.intent')
+ def handle_unmute_intent(self, message):
+- alsa = AlsaControl()
+- self.log.info("User unmuted audio.")
+- alsa.unmute()
+- volume = alsa.get_volume_percent()
+- self.bus.emit(Message("mycroft.volume.get").response({"percent" : volume / 100}))
++ self.bus.emit(message.forward("mycroft.volume.unmute"))
+
+ @intent_file_handler('toggle_mute.intent')
+ def handle_toggle_unmute_intent(self, message):
+- alsa = AlsaControl()
+- alsa.toggle_mute()
+- muted = alsa.is_muted()
+- self.log.info(f"User toggled mute. Result: {'muted' if muted else 'unmuted'}")
+- self.bus.emit(Message("mycroft.volume.get").response(
+- {"percent" : 0 if muted else (alsa.get_volume_percent() / 100)}))
++ self.bus.emit(message.forward("mycroft.volume.mute.toggle"))
+
+ @intent_handler(IntentBuilder("current_volume").require('current_volume'))
+ def handle_query_volume(self, message):
+- volume = AlsaControl().get_volume()
+- self.speak_dialog('volume.is', data={'volume': volume})
++ response = self.bus.wait_for_response(message.forward("volume.get"))
++ if response:
++ volume = response.data["percent"] * 100
++ self.speak_dialog('volume.is', data={'volume': volume})
++ else:
++ # TODO dedicated error dialog
++ raise TimeoutError("Failed to get volume")
+
+
+ def create_skill():