Cave Master - You choose your destiny in a choose your own adventure style game.
Can you reach the end of the cave?
What better way to explore an adventure style game than from a stuffed animal.
In this project we create a Alexa skill to run the logic and access the Alexa web service from the Raspberry Pi and package it in a stuffed animal.
To play cave master on your echo, download the cavemaster skill and say play cave master.
http://alexa.amazon.com/spa/index.html#skills/amzn1.ask.skill.a1991ae3-7761-42b7-973f-ec910e245967
I created the Cava Master story and logic in javascript. Then added the Alexa endpoints using the alexa-sdk library. More information about the alexa-sdk library can be found at https://developer.amazon.com/alexa-skills-kit and code https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs .
Codevar Alexa = require('alexa-sdk');
exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
};
var handlers = {
'LaunchRequest': function () {
var caveMaster = new CaveMaster();
var currentRoom = caveMaster.currentRoom;
var sndPath = encodeURI('https://jimmyalexaskills.azurewebsites.net/' + caveMaster.currentRoom.soundPath);
this.attributes['currentRoom'] = currentRoom.name
this.emit(':ask', "<audio src='" + sndPath + "' />", "what should you do?");
},
'ActionIntent': function () {
var action = this.event.request.intent.slots.ACTION.value;
var currentRoomName = this.attributes['currentRoom'];
var caveMaster = new CaveMaster(currentRoomName);
var newRoom = caveMaster.processSpeech(action);
if (newRoom != null) {
var sndPath = encodeURI('https://jimmyalexaskills.azurewebsites.net/' + newRoom.soundPath);
this.attributes['currentRoom'] = newRoom.name;
var messageAction = "<audio src='" + sndPath + "' />";
this.emit(':ask', messageAction, "what should you do?");
} else {
this.attributes['currentRoom'] = currentRoomName;
this.emit(':ask', "That is not a command you can use in this room. Try, " + caveMaster.getAllActions(caveMaster.currentRoom.nextRooms), "What should you do?");
}
}
};
You can see the full code of CaveMaster working with alexa-sdk at https://github.com/jamesfdickinson/CaveMasterAlexa .
Cave Master has recorded audio for each room. The audio is hosted on azure, but could be hosted anywhere. Alexa will out text or audio when issuing the this.emit(':ask' or this.emit(':tell' command. In our case we used the "ask" command for each response to keep the story dialog going. you will also notice "this.attributes['currentRoom']", this is used to save session data from each command to the next. All cave master needed was the current room. The Cave master code itself comprises of rooms possible options liking to other room each with their own audio.
Alexa web service - Raspberry pi + mic + speaker + stuffed animalThe Alexa web service is access from the raspberry pi with input as mic and output as a speaker. The python code accesses the service and input output logic. Also when connecting to Alexa web service the device needs to authenticate. The python code also includes an authentication web interface. I used the code from https://github.com/sammachin/AlexaPi . My version is slightly modified to exclude the physical button and is alway listening, by commenting out the wait for hardware click.
I pluged in a simple speaker and a usb mic and both worked without issues.
After following the steps outlined on AlexaPi's readme, I could access my Alexa skill from my Raspberry Pi.
Once all the pieces were working, I put the Raspberry Pi indie a stuffed animal and play Cave Master.
Enjoy
Future projects- More stories
- Move mouth
Comments