Repository: MycroftAI/mycroft-core

Issue:
Volume change should not be spoken every time
When changing the volume with hardware it should not speak the result but rather play a sound.



Discussion:

Resolving patch:
diff --git a/mycroft/client/enclosure/enclosure.py b/mycroft/client/enclosure/enclosure.py
--- a/mycroft/client/enclosure/enclosure.py
+++ b/mycroft/client/enclosure/enclosure.py
@@ -78,10 +78,12 @@ def process(self, data):
             kill(['mimic'])  # TODO - Refactoring in favor of Mycroft Stop
 
         if "volume.up" in data:
-            self.client.emit(Message("IncreaseVolumeIntent"))
+            self.client.emit(
+                Message("IncreaseVolumeIntent", metadata={'play_sound': True}))
 
         if "volume.down" in data:
-            self.client.emit(Message("DecreaseVolumeIntent"))
+            self.client.emit(
+                Message("DecreaseVolumeIntent", metadata={'play_sound': True}))
 
     def stop(self):
         self.alive = False
diff --git a/mycroft/skills/volume/__init__.py b/mycroft/skills/volume/__init__.py
--- a/mycroft/skills/volume/__init__.py
+++ b/mycroft/skills/volume/__init__.py
@@ -18,10 +18,13 @@
 
 import time
 from alsaaudio import Mixer
-from os.path import dirname
+from os.path import dirname, join
 
 from adapt.intent import IntentBuilder
+
+from mycroft.client.enclosure import enclosure
 from mycroft.skills.core import MycroftSkill
+from mycroft.util import play_wav
 from mycroft.util.log import getLogger
 
 __author__ = 'jdorleans'
@@ -36,6 +39,7 @@ class VolumeSkill(MycroftSkill):
     def __init__(self):
         super(VolumeSkill, self).__init__(name="VolumeSkill")
         self.default_volume = int(self.config.get('default_volume'))
+        self.volume_sound = join(dirname(__file__), "blop-mark-diangelo.wav")
 
     def initialize(self):
         self.load_data_files(dirname(__file__))
@@ -68,13 +72,23 @@ def handle_set_volume(self, message):
         mixer.setvolume(volume)
         self.speak_dialog('set.volume', data={'volume': code})
 
+    def communicate_volume_change(self, message, dialog, code, changed):
+        play_sound = message.metadata.get('play_sound', False)
+        if play_sound:
+            if changed:
+                play_wav(self.volume_sound)
+        else:
+            if not changed:
+                dialog = 'already.max.volume'
+            self.speak_dialog(dialog, data={'volume': code})
+
     def handle_increase_volume(self, message):
-        code, volume = self.__update_volume(1)
-        self.speak_dialog('increase.volume', data={'volume': code})
+        self.communicate_volume_change(message, 'increase.volume',
+                                       *self.__update_volume(+1))
 
     def handle_decrease_volume(self, message):
-        code, volume = self.__update_volume(-1)
-        self.speak_dialog('decrease.volume', data={'volume': code})
+        self.communicate_volume_change(message, 'decrease.volume',
+                                       *self.__update_volume(-1))
 
     def handle_mute_volume(self, message):
         self.speak_dialog('mute.volume')
@@ -88,14 +102,20 @@ def handle_reset_volume(self, message):
             data={'volume': self.get_volume_code(self.default_volume)})
 
     def __update_volume(self, level=0):
+        """
+        Tries to change volume level
+        :param level: +1 or -1; the step to change by
+        :return: new code (0..11), whether volume changed
+        """
         mixer = Mixer()
         volume = mixer.getvolume()[0]
-        code = self.get_volume_code(volume) + level
-        code = self.fix_code(code)
-        if code in self.VOLUMES:
-            volume = self.VOLUMES[code]
+        old_code = self.get_volume_code(volume)
+
+        new_code = self.fix_code(old_code + level)
+        if new_code in self.VOLUMES:
+            volume = self.VOLUMES[new_code]
             mixer.setvolume(volume)
-        return code, volume
+        return new_code, new_code != old_code
 
     def get_volume(self, message, default=None):
         amount = message.metadata.get('VolumeAmount', default)


Test patch: