Merge pull request #300 from Wolfgange3311999/bugfix/issues-299

The volume knob now plays a noise for feedback
pull/301/head
Arron Atchison 2016-07-21 13:15:59 -05:00 committed by GitHub
commit b5dce51175
5 changed files with 38 additions and 12 deletions

View File

@ -5,4 +5,5 @@ recursive-include mycroft/skills/*/dialog *
recursive-include mycroft/skills/*/vocab *
recursive-include mycroft/skills/*/regex *
include mycroft/skills/alarm/alarm.mp3
include mycroft/skills/volume/blop-mark-diAngelo.wav
#include mycroft/tts/mycroft_voice_4.0.flitevox

View File

@ -78,10 +78,12 @@ class EnclosureReader(Thread):
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

View File

@ -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 @@ class VolumeSkill(MycroftSkill):
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 @@ class VolumeSkill(MycroftSkill):
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)

Binary file not shown.

View File

@ -0,0 +1,3 @@
volume already at max
volume set to max
volume at maximum