Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
74 changes: 69 additions & 5 deletions alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import time
import os
import re
import codecs
from flask import Flask, json, render_template
from flask_ask import Ask, session, question, statement, audio, request, context
from shutil import copyfile
Expand All @@ -29,6 +30,7 @@
if LANGUAGE and LANGUAGE != 'None' and LANGUAGE == 'de':
TEMPLATE_FILE = "templates.de.yaml"
else:
LANGUAGE = 'en'
TEMPLATE_FILE = "templates.en.yaml"

# According to this: https://alexatutorial.com/flask-ask/configuration.html
Expand Down Expand Up @@ -2728,24 +2730,86 @@ def alexa_what_albums(Artist):
return question(response_text)


def get_help_samples(limit=7):
# read example slot values from language-specific file.
sample_slotvals = {}
fn = os.path.join(os.path.dirname(__file__), 'sample_slotvals.%s.txt' % (LANGUAGE))
f = codecs.open(fn, 'rb', 'utf-8')
for line in f:
media_type, media_title = line.encode("utf-8").strip().split(' ', 1)
sample_slotvals[media_type] = media_title.strip()
f.close()

# don't suggest utterances for the following intents, because they depend on
# context to make any sense:
ignore_intents = [
'PlayerMoveUp',
'PlayerMoveDown',
'PlayerMoveLeft',
'PlayerMoveRight',
'PlayerRotateClockwise',
'PlayerRotateCounterClockwise',
'PlayerZoomHold',
'PlayerZoomIn',
'PlayerZoomInMoveUp',
'PlayerZoomInMoveDown',
'PlayerZoomInMoveLeft',
'PlayerZoomInMoveRight',
'PlayerZoomOut',
'PlayerZoomOutMoveUp',
'PlayerZoomOutMoveDown',
'PlayerZoomOutMoveLeft',
'PlayerZoomOutMoveRight',
'PlayerZoomReset'
]

# build complete list of possible utterances from file.
utterances = {}
fn = os.path.join(os.path.dirname(__file__), 'speech_assets/SampleUtterances.%s.txt' % (LANGUAGE))
f = codecs.open(fn, 'rb', 'utf-8')
for line in f:
intent, utterance = line.encode("utf-8").strip().split(' ', 1)
if intent in ignore_intents: continue
if intent not in utterances:
utterances[intent] = []
utterances[intent].append(utterance)
f.close()

# pick random utterances to return, up to the specified limit.
sample_utterances = {}
for k in random.sample(utterances.keys(), limit):
# substitute slot references for sample media titles.
sample_utterances[k] = re.sub(r'{(\w+)?}', lambda m: sample_slotvals.get(m.group(1), m.group(1)), random.choice(utterances[k])).decode("utf-8")

return sample_utterances


@ask.intent('AMAZON.HelpIntent')
def prepare_help_message():
response_text = render_template('help').encode("utf-8")
reprompt_text = render_template('what_to_do').encode("utf-8")
sample_utterances = get_help_samples()

response_text = render_template('help', example=sample_utterances.popitem()[1]).encode("utf-8")
reprompt_text = render_template('help_short', example=sample_utterances.popitem()[1]).encode("utf-8")
card_title = render_template('help_card').encode("utf-8")
samples = ''
for sample in sample_utterances.values():
samples += '"%s"\n' % (sample)
card_text = render_template('help_text', examples=samples).encode("utf-8")
print card_title

if not 'queries_keep_open' in session.attributes:
return statement(response_text).simple_card(card_title, response_text)
return statement(response_text).simple_card(card_title, card_text)

return question(response_text).reprompt(reprompt_text)
return question(response_text).reprompt(reprompt_text).simple_card(card_title, card_text)


# No intents invoked
@ask.launch
def alexa_launch():
sample_utterances = get_help_samples()

response_text = render_template('welcome').encode("utf-8")
reprompt_text = render_template('what_to_do').encode("utf-8")
reprompt_text = render_template('help_short', example=sample_utterances.popitem()[1]).encode("utf-8")
card_title = response_text
print card_title

Expand Down
18 changes: 18 additions & 0 deletions sample_slotvals.de.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Addon YouTube
MovieGenre Komödie
Movie Männertag
Artist Helene Fischer
Album Farbenspiel
MusicGenre Schlager
AudioPlaylist Partymusik
Song Atemlos
Show Farscape
VideoPlaylist HD videos
ShowGenre Science Fiction
MusicVideoGenre Pop
MusicVideo Die Hölle morgen früh
Volume Fünfundsiebzig
Season zwei
Episode acht
ForwardDur eine Minute
BackwardDur 30 Sekunden
18 changes: 18 additions & 0 deletions sample_slotvals.en.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Addon YouTube
MovieGenre Comedy
Movie Tropic Thunder
Artist Sia
Album One Thousand Forms of Fear
MusicGenre Pop
AudioPlaylist Holiday
Song Elastic Heart
Show Farscape
VideoPlaylist HD videos
ShowGenre Science Fiction
MusicVideoGenre Pop
MusicVideo Chandelier
Volume seventy five
Season two
Episode eight
ForwardDur one minute
BackwardDur thirty seconds
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
AMAZON.HelpIntent nach was ich es fragen kann
AMAZON.HelpIntent was es alles kann
AMAZON.HelpIntent was es kann
AMAZON.HelpIntent was ich es fragen kann
AddonExecute führe add on {Addon} aus
AddonExecute führe addon {Addon} aus
AddonExecute führe erweiterung {Addon} aus
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
AMAZON.HelpIntent things to try
AMAZON.HelpIntent what can i ask you
AMAZON.HelpIntent what can you do
AddonExecute execute add on {Addon}
AddonExecute execute addon {Addon}
AddonExecute execute plug in {Addon}
Expand Down
12 changes: 9 additions & 3 deletions templates.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ you_have_episode_list: "Es gibt neue Folgen für {{ items }}"

volume_set: "Lautstärke auf {{ num }} gestellt"

help: "Du kannst mich fragen ob es neue Serien gibt, einen Film, Serie oder Sänger zu spielen, oder die Wiedergabe von Medien zu bedienen"
help: "Du kannst mich fragen, ob es neue Serien gibt, mich bitten einen Film, eine Serie oder die Musik eines Interpreten abzuspielen oder die Wiedergabe von Medien zu steuern und vieles mehr. Zum Beispiel {{ example }}. Ich habe dir weitere Beispiele an deine Alexa App geschickt."

help_short: "Was möchtest du tun? Probiere etwas wie {{ example }}."

help_text: "Kodi-Alexa ermöglicht es dir eine oder mehrere Kodi Installtionen mit deiner Stimme zu steuern. Hier sind einige Beispiele, die du sagen kannst:\n
\xa0\n
{{ example }}
\xa0\n
Für eine komplette Liste der unterstützten Kommandos, lese bitte die README Datei auf Github (https://github.com/m0ngr31/kodi-alexa/README.md)."

help_play: "Spezifiziere bitte den Medientyp mit dem Wiedergabebefehl, so wie Spiele den Film Ghost Busters"

Expand All @@ -176,8 +184,6 @@ are_you_sure_hibernate: "Bist du dir sicher, dass das System in den Hibernate ge

are_you_sure_suspend: "Bist du dir sicher, dass das System in den Suspend gehen soll?"

what_to_do: "Was möchtest Du tun?"

welcome: "Willkommen zum Kodi Skill"

nothing_currently_playing: "Es läuft gerade nichts."
Expand Down
12 changes: 9 additions & 3 deletions templates.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ you_have_episode_list: "There are new episodes of {{ items }}"

volume_set: "Volume set to {{ num }}"

help: "You can ask me whether there are any new shows, to play a movie, tv show, or artist, or control playback of media."
help: "You can ask me whether there are any new shows, to play a movie, t. v. show, or artist, control playback of media, and more. For example, {{ example }}. I've sent more examples to your Alexa app."

help_short: "What would you like to do? Try something like, {{ example }}."

help_text: "Kodi-Alexa allows you to fully control one or more Kodi installations with your voice. Here are some examples of things you can say:\n
\xa0\n
{{ examples }}
\xa0\n
For a complete list of supported requests, please see the README file on Github (https://github.com/m0ngr31/kodi-alexa/README.md)."

help_play: "Please specify the media type in your play command, such as, play the movie ghost busters."

Expand All @@ -176,8 +184,6 @@ are_you_sure_hibernate: "Are you sure you want to hibernate?"

are_you_sure_suspend: "Are you sure you want to suspend?"

what_to_do: "What would you like to do?"

welcome: "Welcome to Kodi."

nothing_currently_playing: "Kodi isn't playing any music right now."
Expand Down
3 changes: 3 additions & 0 deletions utterances.german.txt → utterances.de.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,6 @@ AddonGlobalSearch (suche/suche nach/finde) {Show}
AddonGlobalSearch (suche/suche nach/finde) {Movie}
AddonGlobalSearch (suche/suche nach/finde) {Album}
AddonGlobalSearch (suche/suche nach/finde) {Artist}

AMAZON.HelpIntent (/nach) was ich es fragen kann
AMAZON.HelpIntent was es (/alles) kann
3 changes: 3 additions & 0 deletions utterances.txt → utterances.en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,6 @@ AddonGlobalSearch (find/search for) {Show}
AddonGlobalSearch (find/search for) {Movie}
AddonGlobalSearch (find/search for) {Album}
AddonGlobalSearch (find/search for) {Artist}

AMAZON.HelpIntent what can (you do/i ask you)
AMAZON.HelpIntent things to try