Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: portal ocp #35

Merged
merged 12 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/skill_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ on:
jobs:
py_build_tests:
uses: neongeckocom/.github/.github/workflows/python_build_tests.yml@master
# skill_unit_tests: # One day
# uses: neongeckocom/.github/.github/workflows/skill_tests.yml@master
skill_unit_tests: # One day
uses: neongeckocom/.github/.github/workflows/skill_tests.yml@master
with:
neon_versions: "[3.7, 3.8, 3.9, '3.10', '3.11']"
ovos_versions: "[3.7, 3.8, 3.9, '3.10', '3.11']"
# skill_intent_tests:
# uses: neongeckocom/.github/.github/workflows/skill_test_intents.yml@master
skill_resource_tests:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
.vscode/*

test/skill_fs/*
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ This skill has some spicy language options. It starts in grandma mode by default

If you want to go back into grandma mode, say "I'm too young to die."

## Requirements

Most sounds will play on any device, but longer sounds require OCP to be enabled.
mikejgray marked this conversation as resolved.
Show resolved Hide resolved

## Credits

JarbasAI
Expand Down
62 changes: 48 additions & 14 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# pylint: disable=unused-import,missing-docstring,invalid-name
import random
from os import listdir
from os.path import dirname
from os.path import dirname, join

from ovos_workshop.intents import IntentBuilder
from ovos_workshop.decorators import skill_api_method, intent_handler
from ovos_workshop.skills import OVOSSkill
from ovos_bus_client.apis.ocp import OCPInterface

from .stardate import StarDate
from .constants import SPICY_SOUNDS
from skill_easter_eggs.stardate import StarDate
from skill_easter_eggs.constants import SPICY_SOUNDS


class EasterEggsSkill(OVOSSkill):
def initialize(self):
self.ocp = OCPInterface(bus=self.bus) # pylint: disable=attribute-defined-outside-init

@property
def grandma_mode(self):
return self.settings.get("grandma_mode_enabled", True)
Expand Down Expand Up @@ -79,24 +83,35 @@ def handle_number_of_languages_intent(self, _):

@intent_handler(IntentBuilder("portal_intent").require("portal_keyword").build())
def handle_portal_intent(self, _):
path, files = self.get_reference_files("/sounds/portal", "mp3")
path, files = self.get_reference_files("sounds/portal", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(mp3)
if self.ocp:
self._play_in_ocp(mp3, title="Portal Easter Egg")
else:
mikejgray marked this conversation as resolved.
Show resolved Hide resolved
self.log.warning("OCP not available, playing locally, this is not interruptible so consider enabling OCP")
self.play_audio(mp3)
else:
self.speak_dialog("bad_file")

def get_reference_files(self, path_ending, extension):
path = dirname(__file__) + path_ending
def get_reference_files(self, path_ending: str, extension: str):
"""Get a list of files in a directory

If grandma mode is enabled, filter out spicy sounds
path_ending: str, path to directory, should not start with /
extension: str, file extension to filter by
"""
path_ending = path_ending.strip("/")
path = join(dirname(__file__), path_ending)
if self.grandma_mode:
files = [sound for sound in listdir(path) if f".{extension}" in sound and sound not in SPICY_SOUNDS]
files = [sound for sound in listdir(path) if f".{extension}" in sound and f"{path_ending}/{sound}" not in SPICY_SOUNDS]
else:
files = [sound for sound in listdir(path) if f".{extension}" in sound]
return path, files

@intent_handler(IntentBuilder("hal_intent").require("hal_keyword").build())
def handle_hal_intent(self, _):
path, files = self.get_reference_files("/sounds/hal", "mp3")
path, files = self.get_reference_files("sounds/hal", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(mp3)
Expand All @@ -106,7 +121,7 @@ def handle_hal_intent(self, _):
@intent_handler(IntentBuilder("duke_nukem_intent").require("duke_nukem_keyword").build())
def handle_dukenukem_intent(self, _):
if not self.grandma_mode:
path, files = self.get_reference_files("/sounds/dukenukem", "wav")
path, files = self.get_reference_files("sounds/dukenukem", "wav")
if len(files):
wav = path + "/" + random.choice(files)
self.play_audio(wav)
Expand All @@ -117,7 +132,7 @@ def handle_dukenukem_intent(self, _):

@intent_handler(IntentBuilder("arnold_intent").require("arnold_keyword").build())
def handle_arnold_intent(self, _):
path, files = self.get_reference_files("/sounds/arnold", "wav")
path, files = self.get_reference_files("sounds/arnold", "wav")
if len(files):
wav = path + "/" + random.choice(files)
self.play_audio(wav)
Expand All @@ -126,7 +141,7 @@ def handle_arnold_intent(self, _):

@intent_handler(IntentBuilder("bender_intent").require("bender_keyword").build())
def handle_bender_intent(self, _):
path, files = self.get_reference_files("/sounds/bender", "mp3")
path, files = self.get_reference_files("sounds/bender", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(mp3)
Expand All @@ -135,13 +150,32 @@ def handle_bender_intent(self, _):

@intent_handler(IntentBuilder("glados_intent").require("glados_keyword").build())
def handle_glados_intent(self, _):
path, files = self.get_reference_files("/sounds/glados", "mp3")
path, files = self.get_reference_files("sounds/glados", "mp3")
if len(files):
mp3 = path + "/" + random.choice(files)
self.play_audio(mp3)
if self.ocp:
self._play_in_ocp(mp3, title="GlaDOS says...")
else:
self.log.warning("OCP not available, playing locally, this is not interruptible so consider enabling OCP")
self.play_audio(mp3)
else:
self.speak_dialog("bad_file")

@skill_api_method
def get_display_date(self):
return StarDate().getStardate()

def _play_in_ocp(self, media, title="Easter Egg!"):
data = {
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
"match_confidence": 100,
"media_type": 1, # MediaType.AUDIO
"length": 0,
"uri": media,
"playback": 2, # PlaybackType.AUDIO
"image": "",
"bg_image": "",
"skill_icon": "",
"title": title,
"skill_id": self.skill_id,
}
self.ocp.play(tracks=[data])
4 changes: 4 additions & 0 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
neon-minerva>=0.1.0
ovos_plugin_manager
pytest
pytest-cov
1 change: 1 addition & 0 deletions requirements.txt → requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
python-dateutil
ovos-utils~=0.0, >=0.0.38
ovos_workshop~=0.0, >=0.0.15
ovos_bus_client~=0.0, >=0.0.6
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def find_resource_files():
version=get_version(),
url=f"https://github.com/OpenVoiceOS/{SKILL_NAME}",
license="BSD-3-Clause",
install_requires=get_requirements("requirements.txt"),
install_requires=get_requirements("requirements/requirements.txt"),
author="Jarbas",
author_email="jarbas@openvoiceos.com",
long_description=long_description,
Expand All @@ -102,4 +102,5 @@ def find_resource_files():
package_data={SKILL_PKG: find_resource_files()},
include_package_data=True,
entry_points={"ovos.plugin.skill": PLUGIN_ENTRY_POINT},
extras_require={"test": get_requirements("requirements/requirements-dev.txt")}
)
10 changes: 1 addition & 9 deletions skill.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@
"desktopFile": false,
"warning": "",
"systemDeps": false,
"requirements": {
"python": [
"ovos-utils~=0.0, >=0.0.38",
"ovos_workshop~=0.0, >=0.0.15",
"python-dateutil"
],
"system": {},
"skill": []
},
"requirements": "Most sounds will play on any device, but longer sounds require OCP to be enabled.",
"incompatible_skills": [],
"platforms": [
"i386",
Expand Down
1 change: 1 addition & 0 deletions test/skill_fs/config/mycroft.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Audio": {"backends": {"ocp": {"active": true}}}}
Loading
Loading