Software apps and online services
I first heard about Alexa Voice Services (AVS) in February via a tweet linking a Youtube from Novaspirit Tech.
This details how to install @sammachin's code to run AVS on a Raspberry Pi (RPi). I installed this on my RPi2 and was impressed with the Alexa experience but wanted more! As I am in the UK I am unable to easily buy an Amazon Echo so AVS is the ideal way to experience the power of Alexa.
I moved on to using the Amazon provided AVS Sample app on the RPi2 and then, a couple of weeks later, upgraded this to the new v20160207 app following the excellent notes on the Amazon Github Alexa AVS on Raspberry Pi page.
After creating a simple sample skill from the Amazon guides, I moved on to my first project of a Kid's Dictionary using the Merriam-Webster Inc. dictionary API for their Elementary Dictionary as I have a young child. I used some techniques from the Amazon sample skill called History Buff and developed a skill that is working but suffers from the common problem of the word choices being too broad so it does not always look up the correct word, particularly given my Northern Ireland accent! I still have this as a private skill in my developer account but do not intend to publish it due to this issue.
From the Merriam-Webster website I discovered the Daily Buzzword on their Word Central site for "younger humanoids." I decided this would make a better skill and got to work.
I am not, and never have been, a professional programmer but have picked up Apple BASIC, BBC BASIC, Pascal, C and taken a course in Java in the past. I opted to use node.js for my programming as it is easier to get to grips with particulary for an inexperienced programmer. I used AWS Lambda as it makes implementing the skill easy and is free for Amazon Skills Kit developers!
My first attempt at the Daily Buzzword program used techniques from the History Buff skill to scrape the HTML page source code for the definition of the Daily Buzzword and then read it out. I went through a couple of rounds of certification during which time I decided to add a yes/no option as a simple AMAZON.NoIntent to also read the example usage of the Daily Buzzword. My skill was published in this form initially.
My work on the Kid's Dictionary skill in parsing the API dictionary definition results proved useful as I now had to parse the HTML web page source. The parseHTML function breaks down the HTML page source into the portions I need and puts them into an array for later use. As this is an educational skill, I used a case statement to make sure of the use of the correct grammar when referring to the part of speech, so "a noun" and "an adjective" for example. The definition portion of the web page is taken from the Merriam-Webster API results so I was already familiar with parsing this and dealing with single/multiple definitions and single/multiple senses. I just had to deal with the added HTML tags.
I then read about this Hackster.io competition and was pleased to see it also allowed for entries from non-US residents. I decided my skill needed some added complexity to have any chance at a prize so added in the Daily Buzzword quiz section as well, which required adding session state information and ended up more than tripling the amount of code! This also involved adding several more intents including a couple of custom slot types.
I had been chatting with Jo Jaquinta on the Alexa developer forums and decided to buy the book he co-wrote with Stacy Colella called "How to Program -- Amazon Echo: Design, Development and Testing Alexa Skills". There is a section in this book on "Maintaining Session State" that I realized I would need to implement in the extended Daily Buzzword skill including a quiz section. The Amazon sample skill WiseGuy demonstrates the use of session state so I adopted these techniques in my enhanced program.
The quiz answer and the explanation of the answer are in the HTML page source so my program records in the array which answer is the correct one whilst parsing this section. The scoreQuiz function handles the user's answers dealing with the various possibilities such as: getting the answer correct on the first try; getting the answer correct with more than one try; having only one available answer left; incorrect answers; invalid answers (which do not count toward your guesses) and passing on the answer.
I found the most challenging aspects to be getting used to an action driven event model and separating out intent types properly (I mixed yes and no in the same intent at an early point before I realized my mistake!). Perhaps if I had read more of the documentation I would not have made as many mistakes, but I view them as a learning opportunity anyway!
Once I had my extended program functioning well enough I added in session state aware Help and selected Repeat opportunities.
I added plenty of console log statements to my code so that during development and testing I was able to use AWS Cloudwatch logs to help analyse program flow and errors. I modified and parameterised the URL used in the getPageSourceFromMerriamWebster function to access the Daily Buzzword archive section of the website so I had a year's worth of past buzzwords to test my code. This helped me identify areas where the parsing needed improvement to remove odd characters.
Once the skill was published I made use of an AWS Cloudwatch alert to monitor any errors occurring in the code and was then able to check the Cloudwatch logs to help analyse the error and fix the code.
One Daily Buzzword example usage contained the word Muñoz which appears as Mu & #241; oz (without the spaces - I had to add them to stop it encoding here!) in the page source so I added a piece of code to look for such extended character codes and use the String.fromCharCode() method to convert them back into the correct spoken and written character.
Final Published Skill
I was lucky in that my published skill received a number of 5 star reviews early on that put me at the top of the Skills list displayed in the Alexa app for over a week. This boosted my user numbers considerably and I had good fun asking my kid to guess how many unique users had listened to Daily Buzzword the previous day.
The following three cards from the Alexa iOS app demonstrate the program flow. This first card has the Daily Buzzword "verity" with its definition at the bottom. Above is the example usage of verity, the user having said Yes to hearing the example usage.
The second card shows the quiz for "verity" at the bottom, the user having said Yes to the quiz. In this case the user fails to guess the correct answer so after 3 tries (1 less than the available answers) the program responds with "Bad luck, the answer is A." and asks if the user wishes to hear the explanation.
The final card shows the explanation of the answer. For completeness this card is displayed whether or not the user asks to hear the explanation. If they decline the explanation then it is not read out but the card allows the user to read the (often long) explanation if they wish.
I hope you enjoy using my skill and learn some new words! You can find it in the Skills list here.
I had been going to tackle Hangman as my next skill but the Skillsai team beat me to it! I've a couple of other ideas I am working on as I certainly enjoyed creating my first skill and the challenge of programming for a relatively new voice-activated system. It has got me back into programming for the first time in years and my young kid has been very interested in it so hopefully it will encourage him to learn programming as well. He has been using the excellent Scratch application already and found the Hour of Code Minecraft example very exciting!
Finally, Amazon please bring the Echo and friends to the UK soon :)