Skip to content
This repository has been archived by the owner on Jun 28, 2019. It is now read-only.

Alexa Integration

James Bennett edited this page Mar 25, 2019 · 6 revisions

Research and development into Alexa skills and AWS Lambda

To allow the user to interact with our system using voice commands, we are using an Amazon Echo device. The functionality for this is created by defining a custom 'Skill' which runs on the Echo, and can recognise the user's commands.


Architecture

The following diagram describes how we see this part of the system interacting with our existing Node.js web app.


Skills are built up from numerous components:

  • Invocation Name - ‘Jukebox’

Language set to eng-US to ensure most compatibility.

  • Intents - functions that respond to utterances.

QueueIntent - with sample utterances:

‘To queue Rick Astley’ ‘To queue Hey Ya’ ‘To queue a christmas song’

The logic to power this intent can be coded in Node.js as a AWS Lambda function. That backend logic can then be connected to this interaction/frontend via an ARN. So when a user interacts with our Skill, Alexa sends the request to the AWS Lambda function. The requests and responses are given in JSON format.

  • Build Model - A model is built up from the given sample utterances, this is done by Amazon.
  • Endpoint - A choice between AWS Lambda or an independent HTTPS web service.
  • Supply a ARN to be invoked when users interact with the Skill.
  • AWS Lambda supports Node.JS.
  • Free for 1m requests per month which should suffice for our app.

Basic functionality and parsing the user's input.

On recognising the user's speech as relevant to the QueueIntent, we can get their chosen song with this: const query = handlerInput.requestEnvelope.request.intent.slots.Query.value;, which will then be set to the user's search query for the song they desire.

Adding the user's choice to the queue.

This step was more problematic, as it required an interfacing between the code (hosted on AWS Lambda), and our existing web app, as shown in the architecture diagram. A copy of this code is included in this repository, under the /alexa folder, with a description of its function. The core idea is that a new API route was created (in /routes/spotify.js), this receives POST calls, the given search query is then sent to Spotify, and the first result is added to the queue, if there is one. Such a POST call can then be made from the AWS Lambda codebase.

This POST call is under the QueueIntentHandler, and uses Node's in-built http library, as no dependencies could be added to the Lambda codebase.