Build Your Own Amazon Alexa Smart Speaker With a Raspberry Pi

build-amazon-alexa-raspi

Suddenly, everybody’s talking to their tech. Smartphones, TVs, even lightbulbs—all capable of being controlled with a home assistant. As the Internet of Things takes over your home, you’ll find more devices are suddenly capable of responding to your voice, thanks to virtual assistants like the Amazon Alexa.

If you’ve got a spare Raspberry Pi handy, you don’t need to buy an Amazon Alexa device like the Echo or the Echo Dot, because you can build your own. This tutorial will explain how you can set up the Alexa home assistant on your Raspberry Pi.

Hardware You’ll Need

Before you start building your DIY Raspberry Pi Alexa, you’ll need:

  • Raspberry Pi with Raspbian installed onto a micro-SD card
  • A suitable power supply (5V @ 2.5A recommended)
  • A USB microphone
  • A speaker
  • A PC to set up an Amazon Developer account and with an SSH client

Before you start, and if you haven’t already, you’ll need to enable SSH connections to your Raspberry Pi. If you’d prefer, you can set your Raspberry Pi up using a keyboard, mouse, and monitor. You’ll need a microphone, but if you don’t have one, a USB webcam with a mic will do the same job.

Under normal circumstances, I’d recommend installing Raspbian Lite to keep resource usage down. The script you need to install Alexa fails to install on a standard Raspbian Lite installation, however. To work around this, install GStreamer, a Linux media framework, to allow it to install by running the following via SSH or at a terminal screen:

sudo apt update && sudo apt upgrade
sudo apt install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-pulseaudio

Step 1: Create an Amazon Developer Account and Security Profile

Before you can install the Alexa software, you’ll need to create an Amazon developer account. If you’ve got an existing Amazon account, you can log in and register for an Amazon developer account that way.

Once you’re signed in, go to Alexa on the nav bar, then Alexa Voice Service. Click Get Started, then Products > Create Product.

Amazon Developer Account Registration Process Screen

Give your device a name and a product ID. Choose Device with Alexa built-in and select No to the companion app question. Select Other from the Product category dropdown menu and type Raspberry Pi in the provided box below it. Give it a brief description, such as “Sample Raspberry Pi Alexa build”.

Choose Touch-initiated and Hands-free for end user interactions. You don’t need to worry about choosing an image. Choose No to the four final questions, then click Next.

At the next screen, you’ll be required to create an Amazon security profile to link your security data to your Raspberry Pi Alexa. Click Create New Profile. Choose a name and description, similar to mine below.

Amazon Developer Account Security Profile Registration

At the next step, choose Other devices and platforms, then insert a client ID name (this can be anything you like), agree to the terms and conditions and click Generate ID. You’ll then see a pop up telling you that your product has been created.

Next, enable your profile. Go to the Login with Amazon developer page and select your profile from the dropdown menu, then click Confirm.

Insert a domain like raspberrypi.local into the box provided, then click Save.

Step 2: Download the Amazon Assistants Pi Script

To install Amazon Alexa onto your Raspberry Pi easily, you’ll be using a script called Assistants Pi. This provides an easy method for you to install Alexa without needing to build the SDK manually.

To start, you’ll need to install Git to grab the files you need from the script developer. Connect to your Raspberry Pi using an SSH client or, if you’re not running your Pi headless, open up a terminal and type:

sudo apt install git

Once Git is installed, clone the files you need by typing:

git clone https://github.com/shivasiddharth/Assistants-Pi

You’ll need to make the script files executable. Do that by typing:

cd /home/pi/Assistants-Pi/scripts/
sudo chmod +x installer.sh prep-system.sh service-installer.sh audio-test.sh

Step 3: Pre-Configuration Before Installation

Before you can run the initial Assistants Pi scripts before you can install Alexa, you’ll need to install PIP for Python on your Raspberry Pi. Check it’s installed with the following:

pip --version

You should get a response confirming your version. If you don’t, reinstall PIP using apt.

Python PIP Version Check Terminal Command
If PIP is installed correctly, your next stage is to run the Assistants Pi preparation script, pre-system.sh. Run the following:

sudo /home/pi/Assistants-Pi/scripts/prep-system.sh

This will begin installing any necessary packages for you, as well as check that Raspbian is up-to-date.

Assistants Pi Preparation Terminal Script

Once everything is installed, you’ll be given six options to choose from for your audio and mic config. Most people will need to choose USB-MIC-ON-BOARD-JACK, so hit 3 and press enter. Choose this option if you’re using a USB microphone with a speaker attached to the audio port.

Reboot your Raspberry Pi at this stage by typing:

sudo reboot

Once it’s rebooted, check your audio setup is correct by running the following:

sudo /home/pi/Assistants-Pi/scripts/audio-test.sh

This will run a check of your speaker and mic to make sure your Raspberry Pi works with both.

Step 4: Run the Installation Script

Assuming you had no problems with either the mic or the speaker during your audio test, run the following command to install Alexa to your Raspberry Pi:

sudo /home/pi/Assistants-Pi/scripts/installer.sh

You’ll be given the option to choose to install either Alexa, the Google Home Assistant, or both. The script requires additional steps for the Google Assistant to be installed here, so it’s best to skip this. Choose option to install Alexa only.

Assistants Pi Terminal Script Assistant Installer Menu

You’ll need to enter your client ID. Go back to the Alexa developer portal to find this by clicking on your “product” name. Take note of your Product ID.

Click your product name, click Security Profile, then Other devices and platforms. Use the Client ID found here, then type in your Product ID, before agreeing to the terms and conditions. Type AGREE and hit enter.

Raspberry Pi Alexa SDK Conditions Agreement

The script will run through its installation, installing any other necessary packages it needs. This may take some time to complete. You may need to accept a license or two; just read through and hit Y to any confirmation menus.

Step 5: Final Configuration and Testing

Once the script has finished the installation, you have one final script to run:

sudo /home/pi/Assistants-Pi/scripts/service-installer.sh

Run the following, just to be sure the service starts and is enabled:

sudo systemctl enable alexa.service
sudo systemctl start alexa.service

You’ll then need to register and authorize your Pi. Type the following:

sudo /home/pi/Assistants-Pi/Alexa/startsample.sh

You’ll need to type in a code shown in the terminal screen on a page at the Amazon developer site. Type in the code, click Continue, then Allow.

Amazon Developer Product Access Authorization Page

Assuming your Pi authorization went okay, you should see the sample Alexa script running. Test out your DIY Raspberry Pi Alexa device by saying Alexa followed by a command. For example, Alexa, tell me the time.

Reboot one final time and test your device again by issuing another command, to be sure everything works.

A DIY Amazon Alexa for Your Home

You don’t need to buy an expensive new device for your home to enjoy the benefits of a smart speaker. A spare Raspberry Pi makes for a perfect DIY home assistant, whether you’re building a DIY Alexa or if you want to build your own DIY Google Home instead.

If a smart speaker for your home doesn’t take your fancy, maybe head outdoors and build some rugged Raspberry Pi projects instead.

Read the full article: Build Your Own Amazon Alexa Smart Speaker With a Raspberry Pi



from MakeUseOf http://bit.ly/2IpdYct
via IFTTT
Share on Google Plus

About Oyetoke Toby

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment