Skills ohne Fragen / Datumsbedingte Ausgabe

Hier wird über die Entwicklung von Skills diskutiert.
Antworten
Benutzeravatar

Themenstarter
Commandrer
Beiträge: 3
Registriert: Sa 9. Dez 2017, 16:43

Sa 9. Dez 2017, 16:53

Hallo an alle,

schön dass es ein solches Forum in deutscher Sprache gibt.
Ich wäre sehr froh, wenn Ihr mir weiterhelfen könnt! :)

Bin absoluter Neuzugang bei der Programmierung von Alexa Skills.
Dennoch recht erfolgreich. Zumindest konnte ich bis auf 2 Kleinigkeiten meinen Wunsch verwirklichen.

Eventuell könnt Ihr mir ja bei meinen Probleme helfen.

1. Ich habe einen Skill erfolgreich erstellen und speichern können. Der Skill wird mir auch in meiner Alexaapp angezeigt und ich kann diesen auf aktivieren bzw. deaktivieren. Mein Problem: Ich kann immer nur den Skill mit "öffne" oder "frage" ausführen. Also: "Alexa, öffne/starte Skillname".
Was ich haben möchte ist: "Alexa, Skillname". Ich dachte dafür sind die "Sample Utterances" zuständig. Aber egal was und wie ich dort eintrage, Alexa reagiert nur auf "öffne/starte Skillname". Was mache ich flasch? :P

2. Hier ein Beispiel des Skills, welchen ich editieren möchte:

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/* eslint-disable func-names */
/* eslint quote-props: ["error", "consistent"]*/
/**
* This sample demonstrates a simple skill built with the Amazon Alexa Skills
* nodejs skill development kit.
* This sample supports multiple lauguages. (en-US, en-GB, de-DE).
* The Intent Schema, Custom Slots and Sample Utterances for this skill, as well
* as testing instructions are located at https://github.com/alexa/skill-sample-nodejs-fact
**/

'use strict';

const Alexa = require('alexa-sdk');

const APP_ID = undefined; // TODO replace with your app ID (OPTIONAL).

const languageStrings = {
'en': {
translation: {
FACTS: [
'A year on Mercury is just 88 days long.',
'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
'Venus rotates anti-clockwise, possibly because of a collision in the past with an asteroid.',
'On Mars, the Sun appears about half the size as it does on Earth.',
'Earth is the only planet not named after a god.',
'Jupiter has the shortest day of all the planets.',
'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
'The Sun contains 99.86% of the mass in the Solar System.',
'The Sun is an almost perfect sphere.',
'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
'Saturn radiates two and a half times more energy into space than it receives from the sun.',
'The temperature inside the Sun can reach 15 million degrees Celsius.',
'The Moon is moving approximately 3.8 cm away from our planet every year.',
],
SKILL_NAME: 'Space Facts',
GET_FACT_MESSAGE: "Here's your fact: ",
HELP_MESSAGE: 'You can say tell me a space fact, or, you can say exit... What can I help you with?',
HELP_REPROMPT: 'What can I help you with?',
STOP_MESSAGE: 'Goodbye!',
},
},
'en-US': {
translation: {
FACTS: [
'A year on Mercury is just 88 days long.',
'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
'Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.',
'On Mars, the Sun appears about half the size as it does on Earth.',
'Earth is the only planet not named after a god.',
'Jupiter has the shortest day of all the planets.',
'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
'The Sun contains 99.86% of the mass in the Solar System.',
'The Sun is an almost perfect sphere.',
'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
'Saturn radiates two and a half times more energy into space than it receives from the sun.',
'The temperature inside the Sun can reach 15 million degrees Celsius.',
'The Moon is moving approximately 3.8 cm away from our planet every year.',
],
SKILL_NAME: 'American Space Facts',
},
},
'en-GB': {
translation: {
FACTS: [
'A year on Mercury is just 88 days long.',
'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
'Venus rotates anti-clockwise, possibly because of a collision in the past with an asteroid.',
'On Mars, the Sun appears about half the size as it does on Earth.',
'Earth is the only planet not named after a god.',
'Jupiter has the shortest day of all the planets.',
'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
'The Sun contains 99.86% of the mass in the Solar System.',
'The Sun is an almost perfect sphere.',
'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
'Saturn radiates two and a half times more energy into space than it receives from the sun.',
'The temperature inside the Sun can reach 15 million degrees Celsius.',
'The Moon is moving approximately 3.8 cm away from our planet every year.',
],
SKILL_NAME: 'British Space Facts',
},
},
'de': {
translation: {
FACTS: [
'Ein Jahr dauert auf dem Merkur nur 88 Tage.',
'Die Venus ist zwar weiter von der Sonne entfernt, hat aber höhere Temperaturen als Merkur.',
'Venus dreht sich entgegen dem Uhrzeigersinn, möglicherweise aufgrund eines früheren Zusammenstoßes mit einem Asteroiden.',
'Auf dem Mars erscheint die Sonne nur halb so groß wie auf der Erde.',
'Die Erde ist der einzige Planet, der nicht nach einem Gott benannt ist.',
'Jupiter hat den kürzesten Tag aller Planeten.',
'Die Milchstraßengalaxis wird in etwa 5 Milliarden Jahren mit der Andromeda-Galaxis zusammenstoßen.',
'Die Sonne macht rund 99,86 % der Masse im Sonnensystem aus.',
'Die Sonne ist eine fast perfekte Kugel.',
'Eine Sonnenfinsternis kann alle ein bis zwei Jahre eintreten. Sie ist daher ein seltenes Ereignis.',
'Der Saturn strahlt zweieinhalb mal mehr Energie in den Weltraum aus als er von der Sonne erhält.',
'Die Temperatur in der Sonne kann 15 Millionen Grad Celsius erreichen.',
'Der Mond entfernt sich von unserem Planeten etwa 3,8 cm pro Jahr.',
],
SKILL_NAME: 'Weltraumwissen auf Deutsch',
GET_FACT_MESSAGE: 'Hier sind deine Fakten: ',
HELP_MESSAGE: 'Du kannst sagen, „Nenne mir einen Fakt über den Weltraum“, oder du kannst „Beenden“ sagen... Wie kann ich dir helfen?',
HELP_REPROMPT: 'Wie kann ich dir helfen?',
STOP_MESSAGE: 'Auf Wiedersehen!',
},
},
};

const handlers = {
'LaunchRequest': function () {
this.emit('GetFact');
},
'GetNewFactIntent': function () {
this.emit('GetFact');
},
'GetFact': function () {
// Get a random space fact from the space facts list
// Use this.t() to get corresponding language data
const factArr = this.t('FACTS');
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];

// Create speech output
const speechOutput = this.t('GET_FACT_MESSAGE') + randomFact;
this.emit(':tellWithCard', speechOutput, this.t('SKILL_NAME'), randomFact);
},
'AMAZON.HelpIntent': function () {
const speechOutput = this.t('HELP_MESSAGE');
const reprompt = this.t('HELP_MESSAGE');
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
'AMAZON.StopIntent': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
};

exports.handler = function (event, context) {
const alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
// To enable string internationalization (i18n) features, set a resources object.
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Die Experten unter euch werden diesen Skill schnell erkennen. Es ist der Basis FactSkill, welcher Fakten über das Weltall ausgibt, wenn der Sprachbefehl eingeht. Ich habe nun den Wunsch, dass Alexa nicht irgend einen Fakt auswirft, sondern dies vom Datum abhängig ist. Also quasi:

01.01.2018 wird immer Fakt1 ausgegeben
02.01.2018 wird immer Fakt2 ausgegeben usw.

Ich Bedanke mich jetzt schon im Voraus für eure Hilfe! :)
Gruß
Commandrer
0 x
Benutzeravatar

Digi-Kai
Beiträge: 25
Registriert: Do 9. Nov 2017, 08:43
Vorhandene Echos: 4
Vorhandene Echo Dots: 1
Vorhandene Echo Shows: 1

So 10. Dez 2017, 22:13

In Bezug auf deine erste Frage befürchte ich wird es keinen anderen Weg geben, als den Skill über die Aktivierungswörter 'frage' oder 'starte' zu aktivieren.

Das zweite Problem sollte sich doch aber recht leicht lösen lassen. Per getday() sollte doch der Tag ausgelesen werden können.
Statt dem Random Befehl aus deinem Beispiel, sollte dann doch gezielt der Fact an der entsprechenden Position im Array ausgegeben werden können.
0 x
Benutzeravatar

Digi-Kai
Beiträge: 25
Registriert: Do 9. Nov 2017, 08:43
Vorhandene Echos: 4
Vorhandene Echo Dots: 1
Vorhandene Echo Shows: 1

Mo 11. Dez 2017, 09:03

Jetzt wäre es ja mal interessant zu wissen, was dein Skill tatsächlich an Infos "ansagen" soll.
Wäre ja mal nett, wenn du die praktische Anwendung beschreibst.

Hier wäre die fertige Lösung:
Tausche einfach den Code der Get Fact Funktion gegen den folgenden Code aus.
Vergesse nicht dein Fakten-Array mit mindestens 31 Fakten zu füllen, sonst fällt die Funktion auf die Nase.

Verstecken ist aktiviert
Um diesen versteckten Text lesen zu können, mußt du registriert und angemeldet sein.

Deinen Skill kannst du jetzt einfach z.b. mit "Alexa, starte meine Tagesinfo".
Beim heutigen Datum (11.Dez. 2017) würde Alexa dir den 11. Fakt ausgeben.
Soweit ok?

Viel Spass damit.

Grüße
Digi-Kai
Zuletzt geändert von Digi-Kai am Mo 11. Dez 2017, 10:23, insgesamt 1-mal geändert.
0 x
Benutzeravatar

Themenstarter
Commandrer
Beiträge: 3
Registriert: Sa 9. Dez 2017, 16:43

Mo 11. Dez 2017, 13:22

Hallo Digi-Kai,

vielen VIELEN Dank für deine schnelle und kompetente Antwort.
In Ordnung. Dann werde ich einfach den Skill mit "Öffne Fakten" eröffnen. Ich wollte nur wissen, ob das so richtig ist. :)

Der Skill ist für meinen Vater gedacht. Quasi eine Art Witz-Skill, welcher jeden Tag einen neuen Internen Witz erzählen soll.
Mein Ziel wäre, dass ich zum Beispiel 30 Witze aufschreibe, welche sich dann ruhig alle 30 Tage wiederholen können. Das heißt heute Kommt Witz 11, dann 12, dann 13. Aber es ist nicht schlimm, wenn am 14. (durch ein Schaltjahr oder ein anderes Ereignis) die Witze verschieben. Wichtig ist, dass fortlaufend jeden Tag ein anderer Witz erzählt wird.

Noch toller wäre es natürlich, wenn Alexa sagt: "Hier ist dein Witz vom {Datum}": Witz 1

Hier nochmal mein Code, welchen ich verwenden möchte. Ich habe die Fakten jetzt einfach mal durch "Witz 1" usw. ersetzt. Ich wäre dir super dankbar, wenn du diesen einfach so editieren köntest, wie oben beschrieben. Die Witze füge ich dann wieder selbst ein.

Nochmal vielen Dank!
Gruß
Commandrer :)

/* eslint-disable func-names */
/* eslint quote-props: ["error", "consistent"]*/
/**
* This sample demonstrates a simple skill built with the Amazon Alexa Skills
* nodejs skill development kit.
* This sample supports multiple lauguages. (en-US, en-GB, de-DE).
* The Intent Schema, Custom Slots and Sample Utterances for this skill, as well
* as testing instructions are located at https://github.com/alexa/skill-sample-nodejs-fact
**/

'use strict';

const Alexa = require('alexa-sdk');

const APP_ID = undefined; // TODO replace with your app ID (OPTIONAL).

const languageStrings = {
'en': {
translation: {
FACTS: [
'A year on Mercury is just 88 days long.',
'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
'Venus rotates anti-clockwise, possibly because of a collision in the past with an asteroid.',
'On Mars, the Sun appears about half the size as it does on Earth.',
'Earth is the only planet not named after a god.',
'Jupiter has the shortest day of all the planets.',
'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
'The Sun contains 99.86% of the mass in the Solar System.',
'The Sun is an almost perfect sphere.',
'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
'Saturn radiates two and a half times more energy into space than it receives from the sun.',
'The temperature inside the Sun can reach 15 million degrees Celsius.',
'The Moon is moving approximately 3.8 cm away from our planet every year.',
],
SKILL_NAME: 'Space Facts',
GET_FACT_MESSAGE: "Here's your fact: ",
HELP_MESSAGE: 'You can say tell me a space fact, or, you can say exit... What can I help you with?',
HELP_REPROMPT: 'What can I help you with?',
STOP_MESSAGE: 'Goodbye!',
},
},
'en-US': {
translation: {
FACTS: [
'A year on Mercury is just 88 days long.',
'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
'Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.',
'On Mars, the Sun appears about half the size as it does on Earth.',
'Earth is the only planet not named after a god.',
'Jupiter has the shortest day of all the planets.',
'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
'The Sun contains 99.86% of the mass in the Solar System.',
'The Sun is an almost perfect sphere.',
'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
'Saturn radiates two and a half times more energy into space than it receives from the sun.',
'The temperature inside the Sun can reach 15 million degrees Celsius.',
'The Moon is moving approximately 3.8 cm away from our planet every year.',
],
SKILL_NAME: 'American Space Facts',
},
},
'en-GB': {
translation: {
FACTS: [
'A year on Mercury is just 88 days long.',
'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
'Venus rotates anti-clockwise, possibly because of a collision in the past with an asteroid.',
'On Mars, the Sun appears about half the size as it does on Earth.',
'Earth is the only planet not named after a god.',
'Jupiter has the shortest day of all the planets.',
'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
'The Sun contains 99.86% of the mass in the Solar System.',
'The Sun is an almost perfect sphere.',
'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
'Saturn radiates two and a half times more energy into space than it receives from the sun.',
'The temperature inside the Sun can reach 15 million degrees Celsius.',
'The Moon is moving approximately 3.8 cm away from our planet every year.',
],
SKILL_NAME: 'British Space Facts',
},
},
'de': {
translation: {
FACTS: [
'Witz 1',
'Witz 2',
'Witz 3'
],
SKILL_NAME: 'Weltraumwissen auf Deutsch',
GET_FACT_MESSAGE: 'Hier ist die Schönische Weisheit Nummer',
HELP_MESSAGE: 'Du kannst sagen, „Nenne mir einen Fakt über den Weltraum“, oder du kannst „Beenden“ sagen... Wie kann ich dir helfen?',
HELP_REPROMPT: 'Wie kann ich dir helfen?',
STOP_MESSAGE: 'Auf Wiedersehen!',
},
},
};

const handlers = {
'LaunchRequest': function () {
this.emit('GetFact');
},
'GetNewFactIntent': function () {
this.emit('GetFact');
},
'GetFact': function () {
// Get a random space fact from the space facts list
// Use this.t() to get corresponding language data
const factArr = this.t('FACTS');
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];

// Create speech output
const speechOutput = this.t('GET_FACT_MESSAGE') + randomFact;
this.emit(':tellWithCard', speechOutput, this.t('SKILL_NAME'), randomFact);
},
'AMAZON.HelpIntent': function () {
const speechOutput = this.t('HELP_MESSAGE');
const reprompt = this.t('HELP_MESSAGE');
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
'AMAZON.StopIntent': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
};

exports.handler = function (event, context) {
const alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
// To enable string internationalization (i18n) features, set a resources object.
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};
0 x
Benutzeravatar

Digi-Kai
Beiträge: 25
Registriert: Do 9. Nov 2017, 08:43
Vorhandene Echos: 4
Vorhandene Echo Dots: 1
Vorhandene Echo Shows: 1

Mo 11. Dez 2017, 16:09

Commandrer hat geschrieben:
Mo 11. Dez 2017, 13:22
Ich wäre dir super dankbar, wenn du diesen einfach so editieren köntest, wie oben beschrieben. Die Witze füge ich dann wieder selbst ein.
Nicht ernst gemeint oder?
Ich habe doch in meinem ersten Beitrag genau geschrieben, was im Code ausgetauscht werden muss.

Willst du deinen Witze mehrsprachig haben? Dann nimm auch gleich die ganzen Übersetzungen von den Weltraumfacts raus.
Wenn du zusätzlich in der Ausgabe zum Witz auch das Tagesdatum haben willst, füge es doch einfach ein.

Code: Alles auswählen

const speechOutput =  "Hier kommt der Witz vom " + GetDate(Now) + DayFact; 
Das Datum muss für die deutsche Ausgabe noch formatiert werden, muss du mal schauen.

Wenn ich dich richtig verstanden habe, benötigtst du aber doch eigentlich den Tag für die Ausgabe der Witze überhaupt nicht.
Lese deine Daten, wie beim WeltraumFactSkill per Zufall aus. Um zuvermeiden, dass ein Witz doppelt auftauchten lösche sie temporär aus dem Witzereportoire. Das wäre der Code:

Code: Alles auswählen

//per Zufall Witz auswählen
var index = [(Math.random()*facts.length)|0];
var item = facts[index];
//Witz aus Reportoire löschen
facts.splice(index,1);
Du könntest sogar prüfen, ob alle Witze erzählt wurden und dann perSprachbefehl bei Bedarf das Witze Reportoir wieder zurücksetzen, so dass wieder von vorne angefangen werden kann.

Code: Alles auswählen

 if (facts.length <1){
            this.emit(':ask', ("Ich habe leider keine weiteren Witze mehr.... )); 
        }
So funktioniert dein Witze Skill unabhängig vom Tag und von der Anzahl der vorhandenen Witze; egal ob einer oder 1000.
Den ganzen Code könnte man so auf nur ein paar wenige Zeilen einschrumpfen.
0 x
Benutzeravatar

Themenstarter
Commandrer
Beiträge: 3
Registriert: Sa 9. Dez 2017, 16:43

Mo 11. Dez 2017, 20:36

@ Digi-Kai
Sorry aber ich weiß nicht, wo ich den Code einfügen soll. Auch wenn du davon ausgehst, dass du es ganz genau beschrieben hast.
Ich habe leider nicht so viel Ahnung von der Materie. Ich weiß also nicht wo der GetFact eingefügt werden soll oder nicht.
Ich habe mir diesen Code zusammengestückelt und kenne nicht wirklich die Funktionen.

Die englische Übersetzung brauche ich nicht. Ich habe aber Angst den Code zu verändern. Darum lasse ich den ganzen Klumpatsch einfach stehen :)

Nochmal meine Bitte:
Könntest du den Code Fix und Fertig einfügen und posten? :)
0 x
Antworten

Zurück zu „Fähigkeiten (Skills) entwickeln“

  • Information