As engineers at Audible, we’re always curious and exploring ways to enrich our lives with technology.  Also, as a subsidiary of Amazon, we have the chance to experience working with awesome devices and technology such as Alexa, which is really fun and cool.

Path Tracker - Writing an Alexa Skill to get your local train times

I’ve had the Amazon Echo for a while. Recently, I had some time on my hands and decided to build a skill that I would find useful. Typically, my wife and I talk with Alexa to ask her for the weather; we also use Echo to set timers when doing the laundry, set short term reminders, and occasionally to play music or audiobooks.

Before leaving for work, both my wife and I check public transit times. I thought it’d be cool if Alexa could tell us the times instead of us having to look them up on our phones. With this in mind, I searched around for PATH train schedules (trains from New York City to New Jersey) and how to access that information programatically. It turns out the Port Authority has this available to developers in the GTFS format. After reading the GTFS Reference and playing around with the PATH feed, it only took me a couple of hours to wrap my head around it and come up with a simple way to find train times between any two stations.

After I had a working version of the train times algorithm coded, I proceeded to read the documentation for the Alexa skills programming model. The documentation is a little dry but starts making sense as you code up and test your skill. I found the Big Nerd Ranch youtube videos to be very helpful in getting a general feel of the programming model.

I make it a point to draw diagrams before writing a single line of code; this really helps me crystallize my understanding. It’s also really easy to get feedback and a review of the diagram. Here’s the interaction diagram for our Path Tracker skill:

Alt Text

I had initially planned to host the back end as a service on one of my raspberry pis but, due to the number of hoops that Amazon makes you jump through for a self hosted service, I ended up leaning towards AWS Lambda. It was a bit of a pain to get started with Lambda as the support community is rather limited; you’ll need to figure out some of the things yourself by trial and error. (I had no luck at (AWS forums)[https://forums.aws.amazon.com/thread.jspa?threadID=238933] and very little at StackOverflow, although, in general, StackOverflow seems to be a much better place to ask your questions and get some help.)

Once you overcome the initial challenges with running your skill on AWS Lambda, it’s actually a fun platform to develop on. Going into this project, I was no fan of Lambda but ended up a believer in the Zero Infrastructure and configuration model to host code. I think this is something that’s most certainly going to catch on. I do have some complaints about performance for a cold start but I reckon that this is only going to get better with time.

After everything was done and I had tested the functionality with my local Echo device, I submitted the skill for certification. A few days later, I heard back from the certification team that my skill was rejected.

I got this response -

Issues with skill in English (US):

When attempting to invoke the skill with your second and third example phrases, the skill fails to recognize the phrases. The example phrases must function without error since these are interactions that users are most likely to try. Please see test case 3.1 from our Submission Checklist for guidance on example phrases.

Example:

User: “Alexa Ask Path Tracker When is the next train between Exchange Place and Newark” / “Alexa Ask Path Tracker Train to Exchange Place from Newark”

The skill fails to recognize the phrases.

I spent an hour or so trying to figure out why the skill won’t recognize the phrase and came to a conclusion that maybe Newark wasn’t the best station to list on the sample interaction. I recalled that I didn’t know how to pronounce it either before I’d moved to the US, so I changed the sample to:

Alexa Ask Path Tracker What time is the next train from Grove Street to World Trade Center

And submitted the skill for certification again. Voila! After a couple of days, I got an email to let me know that my skill was now live.

For those who are curious about the code, the source code is available at Github. Feel free to share your feedback or certification experience.