From 32f1031ba320c38967327233b558f2fc1d96570c Mon Sep 17 00:00:00 2001 From: Nicolas Marcq Date: Thu, 27 Feb 2020 09:47:27 +0100 Subject: [PATCH 1/4] [Fix] Fix security issue by upgrading ansible version --- docker/testing_debian10.dockerfile | 4 +++- docker/testing_ubuntu_18_04.dockerfile | 6 ++++-- setup.py | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docker/testing_debian10.dockerfile b/docker/testing_debian10.dockerfile index 8444d901..c5b6c954 100644 --- a/docker/testing_debian10.dockerfile +++ b/docker/testing_debian10.dockerfile @@ -8,10 +8,12 @@ RUN apt-get update && apt-get install -y \ git python3-dev libpython3-dev libsmpeg0 libttspico-utils libsmpeg0 flac \ libffi-dev libffi-dev libssl-dev portaudio19-dev build-essential \ sox libatlas3-base mplayer wget vim sudo locales \ - python3-pip pulseaudio-utils libasound2-plugins python3-pyaudio libasound-dev \ + python3-distutils pulseaudio-utils libasound2-plugins python3-pyaudio libasound-dev \ libportaudio2 libportaudiocpp0 ffmpeg \ && rm -rf /var/lib/apt/lists/* +RUN wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py +RUN pip3 install pyaudio "ansible==2.9.5" #RUN pip3 install pyaudio # add a standart user diff --git a/docker/testing_ubuntu_18_04.dockerfile b/docker/testing_ubuntu_18_04.dockerfile index c267b462..c47c6251 100644 --- a/docker/testing_ubuntu_18_04.dockerfile +++ b/docker/testing_ubuntu_18_04.dockerfile @@ -8,11 +8,13 @@ RUN apt-get update && apt-get install -y \ git python3-dev libsmpeg0 libttspico-utils libsmpeg0 flac \ libffi-dev libffi-dev libssl-dev portaudio19-dev build-essential \ sox libatlas3-base mplayer wget vim sudo locales alsa-base alsa-utils \ - python3-pip pulseaudio-utils libasound2-plugins python3-pyaudio libasound-dev \ + python3-distutils pulseaudio-utils libasound2-plugins python3-pyaudio libasound-dev \ libportaudio2 libportaudiocpp0 ffmpeg \ && rm -rf /var/lib/apt/lists/* -RUN pip3 install pyaudio +RUN wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py + +RUN pip3 install pyaudio "ansible==2.9.5" # set UTF-8 ARG lang=en_US diff --git a/setup.py b/setup.py index 9263f90a..bf4fbabb 100644 --- a/setup.py +++ b/setup.py @@ -72,13 +72,14 @@ def package_files(directory): python_requires=">=3.6", # required libs install_requires=[ + 'Werkzeug==0.16.1', 'pyyaml>=5.1', 'six>=1.12.0', 'SpeechRecognition>=3.8.1', 'markupsafe>=1.1.1', 'pyaudio>=0.2.11', 'pyasn1>=0.4.5', - 'ansible>=2.8.1,<2.9', + 'ansible>=2.9.5', 'jinja2>=2.10.1', 'cffi>=1.12.3', 'ipaddress>=1.0.17', From 64d51c11c1fe0a8054e7b2e55b564622a518aece Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 27 Feb 2020 22:30:56 +0100 Subject: [PATCH 2/4] [Feature] add volume neuron --- docs/brain/neurons/volume.md | 68 +++++++++++++++++++++++ kalliope/neurons/volume/__init__.py | 0 kalliope/neurons/volume/volume.py | 83 +++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 docs/brain/neurons/volume.md create mode 100644 kalliope/neurons/volume/__init__.py create mode 100644 kalliope/neurons/volume/volume.py diff --git a/docs/brain/neurons/volume.md b/docs/brain/neurons/volume.md new file mode 100644 index 00000000..387a85c9 --- /dev/null +++ b/docs/brain/neurons/volume.md @@ -0,0 +1,68 @@ +Update the volume + +## Input parameters + +| parameter | required | type | default | choices | comment | +|:----------|:---------|:-------|:--------|:----------------|:-----------------------------------------------------------------------------------| +| level | yes | int | None | | The volume level to set or increase or decrease depending of the selected 'action' | +| action | no | string | set | set,raise,lower | The action to apply to the volume | + +Action type: + +- **set:** set the 'level' value as new volume level +- **raise:** increase the current volume level with the value provided in 'level' +- **lower:** decrease the current volume level with the value provided in 'level' + +## Returned values + +| name | description | type | sample | +|:--------------|:---------------------------------------|:-------|:-------| +| asked_level | The level variable sent to the neuron | int | 22 | +| asked_action | The action variable sent to the neuron | string | set | +| current_level | The current volume level on the system | int | 50 | + + +## Synapses example + +Set the volume to 50% +```yaml +- name: "set-volume" + signals: + - order: "set the volume to 50" + neurons: + - volume: + level: "50" +``` + +Set the volume dynamically +```yaml +- name: "set-volume-dynamic" + signals: + - order: "set the volume to {{ volume }}" + neurons: + - volume: + level: "{{ volume }}" +``` +>**Note:** Depending of your STT engine, the caught 'volume' variable can be a string. For example "twenty" instead of "20". + +Raise the volume +```yaml +- name: "raise-volume" + signals: + - order: "raise the volume" + neurons: + - volume: + level: "10" + action: "raise" +``` + +Reduce the volume +```yaml +- name: "lower-volume" + signals: + - order: "reduce the volume" + neurons: + - volume: + level: "10" + action: "lower" +``` diff --git a/kalliope/neurons/volume/__init__.py b/kalliope/neurons/volume/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/kalliope/neurons/volume/volume.py b/kalliope/neurons/volume/volume.py new file mode 100644 index 00000000..bf644740 --- /dev/null +++ b/kalliope/neurons/volume/volume.py @@ -0,0 +1,83 @@ +import logging + +from kalliope.core import NeuronModule +import alsaaudio + +from kalliope.core.NeuronModule import InvalidParameterException + +logging.basicConfig() +logger = logging.getLogger("kalliope") + + +class SoundManager(object): + + try: + m = alsaaudio.Mixer() + except alsaaudio.ALSAAudioError: + # no master, we are on a Rpi + try: + m = alsaaudio.Mixer("PCM") + except alsaaudio.ALSAAudioError: + # no audio config at all + m = None + + @classmethod + def set_volume(cls, volume_level): + if cls.m is not None: + cls.m.setvolume(int(volume_level)) + + @classmethod + def get_volume(cls): + if cls.m is not None: + vol = cls.m.getvolume() + return int(vol[0]) + return None + + +class Volume(NeuronModule): + + def __init__(self, **kwargs): + super(Volume, self).__init__(**kwargs) + + self.level = kwargs.get('level', None) + self.action = kwargs.get('action', "set") # can be set, raise or lower + + # check parameters + if self._is_parameters_ok(): + if self.action == "set": + logger.debug("[Volume] set volume to: {}".format(self.level)) + SoundManager.set_volume(self.level) + if self.action == "raise": + current_level = SoundManager.get_volume() + level_to_set = self.level + current_level + if level_to_set > 100: + level_to_set = 100 + logger.debug("[Volume] set volume to: {}".format(level_to_set)) + SoundManager.set_volume(level_to_set) + if self.action == "lower": + current_level = SoundManager.get_volume() + level_to_set = self.level - current_level + if level_to_set < 0: + level_to_set = 0 + logger.debug("[Volume] set volume to: {}".format(level_to_set)) + SoundManager.set_volume(level_to_set) + + message = { + "asked_level": self.level, + "asked_action": self.action, + "current_level": SoundManager.get_volume() + } + self.say(message) + + def _is_parameters_ok(self): + if self.level is None: + raise InvalidParameterException("[Volume] level need to be set") + try: + self.level = int(self.level) + except ValueError: + raise InvalidParameterException("[Volume] level '{}' is not a valid integer".format(self.level)) + if self.level < 0 or self.level > 100: + raise InvalidParameterException("[Volume] level need to be placed between 0 and 100") + if self.action not in ["set", "raise", "lower"]: + raise InvalidParameterException("[Volume] action can be 'set', 'raise' or 'lower'") + return True From 64b336309e42539d8048d33ea34a5174d7d4b9c2 Mon Sep 17 00:00:00 2001 From: Nicolas Marcq Date: Fri, 28 Feb 2020 10:46:43 +0100 Subject: [PATCH 3/4] [Fix] #596 fix Ubuntu installation doc --- docs/installation/ubuntu.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation/ubuntu.md b/docs/installation/ubuntu.md index 97fd42b0..eb9897c4 100644 --- a/docs/installation/ubuntu.md +++ b/docs/installation/ubuntu.md @@ -8,7 +8,7 @@ Install some required system libraries and software: ```bash sudo apt update -sudo install -y \ +sudo apt install -y \ git python3-dev python3.7-dev libsmpeg0 libttspico-utils flac \ libffi-dev libssl-dev portaudio19-dev build-essential \ sox libatlas3-base mplayer wget vim sudo locales alsa-base alsa-utils \ From 7e224ba478dc6d46d4df8606f76f1d65c7061916 Mon Sep 17 00:00:00 2001 From: nico Date: Sat, 29 Feb 2020 13:54:56 +0100 Subject: [PATCH 4/4] add volume doc to the official doc --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index e52abdf4..c0998d7f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -73,6 +73,7 @@ pages: - sleep: "brain/neurons/sleep.md" - systemdate: "brain/neurons/systemdate.md" - uri: "brain/neurons/uri.md" + - volume: "brain/neurons/volume.md" - Community modules: "brain/community_modules.md" - CLI: "cli.md" - API: