Introduction: DIY Amazon Alexa

Picture of DIY Amazon Alexa

The Amazon Alexa is a marvelous piece of technology. It has revolutionized how we interact with our environment using technology and how we receive information.

Getting into the IoT category is hard if you are trying to not buy something pre-built. There are many solutions that offer it in a simpler way but why not do it the nitty gritty way and do it yourself!

It is not as hard as you think to do something like this. There isn't even any soldering required!

Here is what you will need:

  • A Raspberry Pi (Zero W preferably or 3 B - Either work)
  • Micro SD card (At least 8GB)
  • A micro USB cable (I had a micro USB adapter that would plug into the wall directly)
  • A charging brick (If you do not have an all in one adapter)
  • A USB microphone (You can pick up a PS Eye or use any other USB microphone)
  • Speaker (3.5mm or bluetooth - 3.5 preferably)
  • Internet connection

Step 1: Setting Up the Pi

Picture of Setting Up the Pi

I used Raspbian for my Raspberry Pi. You can use NOOBS but I would say that Raspbian works better for this purpose.

Windows:

  1. Download Raspbian and insert your Micro SD card (adapter may be needed)
  2. Download Win32diskimager
  3. Open Win32diskimager
  4. Browse to Raspbian .img
  5. Write to disk MAKE SURE YOU SELECT THE RIGHT DISK
  6. Eject disk

MacOS:

  1. Download Raspian and insert your Micro SD card (adapter may be needed)
  2. Download Etcher
  3. Open Etcher
  4. Browse to Raspbian .img
  5. Write to disk MAKE SURE YOU SELECT THE RIGHT DISK
  6. Eject disk

If you are planning on using SSH instead of a display with keyboard and mouse follow these steps below:

  1. Insert the Micro SD card again (adapter may be needed)
  2. Open the SD card files
  3. Create a BLANK file (you can copy and paste config.txt, rename, and remove all contents)
  4. Name it SSH
  5. Eject disk

Next:

  1. Put Micro SD in the Pi
  2. Connect ethernet to Pi
  3. Connect power to Pi

Give the Pi a couple of seconds to boot up then open terminal.

If you are using SSH:

  1. Download Fing or some other network IP scanner
  2. Scan your network (same one Pi is connected to)
  3. Find IP of "raspberry pi"
  4. Ex: 192.168.x.x
  5. If on Mac: Open terminal; type "ssh pi@192.168.x.x(The IP you JUST got from fing)"; password is "raspberry"
  6. If on Windows: Download Putty; type "pi@192.168.x.x(The IP you JUST got from fing)"; password is "raspberry"
  7. You should be in!

Step 2: Getting Your Amazon Account Ready.

  1. Login at https://developer.amazon.com and go to ALEXA, then Alexa Voice Service.
  2. Register a Product Type > Device.
  3. You are at Device Type Info left tab.
    1. For the Device Type ID and Display Name use something like AlexaPi or whatever you want.
  4. You are at Security Profile left tab.
    1. From the drop-down menu choose Create a new profile.
    2. Choose whatever for Security Profile Name and Security Profile Description.
    3. Hit Next.Under Web Settings horizontal tab hit Edit and:
      1. Allowed Origins put
      2. http://localhost:5050 and http://ALEXA.DEVICE.IP.ADDRESS:5050
      3. replace ALEXA.DEVICE.IP.ADDRESS with the IP that you got from fing. This is especially necessary when you are installing from another computer than your Pi is going to run on.
      4. Allowed Return URLs put
      5. http://localhost:5050/code and http://ALEXA.DEVICE.IP.ADDRESS:5050/code
      6. replace ALEXA.DEVICE.IP.ADDRESS with the IP that you got from fing. This is especially necessary when you are installing from another computer than your Pi is going to run on.
    4. Fill in the rest (if there is anything to fill out)

Credit to AlexaPi github repository for some content above.

Step 3: Installing AlexaPi

Enter sudo by entering:

sudo su

Navigate to /opt:

cd /opt

Update and install git:

apt-get update && apt-get upgrade
apt-get -y install git nano

Clone the AlexaPi repo:

git clone <a href="https://github.com/alexa-pi/AlexaPi.git" rel="nofollow"> https://github.com/alexa-pi/AlexaPi.git</a><br>

Start the setup script:

sudo ./AlexaPi/src/scripts/setup.sh

Follow the instructions and copy and paste information from Amazon's Developer site

Credit to AlexaPi github repository for some content above.

Step 4: Post-installation

To run AlexaPi reboot or run:
sudo systemctl start AlexaPi.service

Check status of AlexaPi:

<p>sudo systemctl status AlexaPi.service</p>

Now you want to create the AlexaPi user:

<p>chown -R alexapi:alexapi /var/lib/AlexaPi/<br>usermod --home /var/lib/AlexaPi alexapi</p>

Next:

<p>sudo adduser pulse audio</p><p>sudo adduser pi pulse-access</p><p></p><p>sudo adduser alexapi pulse-access</p>

Now you need to edit a file, open:

<p>sudo nano /etc/systemd/system/pulseaudio.service</p>

In the new blank file write:

<p>[Unit]<br>Description=PulseAudio Daemon</p><p>[Install]
WantedBy=multi-user.target</p><p>[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/bin/pulseaudio --system --realtime --disallow-exit --no-cpu-limit</p>

Save by entering "[ctrl] + x & y & [enter]"

Now run the following command to ensure that pulse runs:

<p>sudo systemctl enable pulseaudio.service</p>

Lastly we need to edit the config file for AlexaPi:

nano /etc/opt/AlexaPi/config.yaml

In the sound section change the following values:

<p>input_device: "pulse"<br>output: "pulse"
output_device: ""</p>

I would recommend installing VLC:

<p>apt-get -y install vlc</p>

and finally:

reboot

Credit to AlexaPi github repository for some content above.

Step 5: The Working Alexa

Picture of The Working Alexa

By now, the Alexa should have rebooted and said "Hello".

Now you say, "Alexa", it will respond with "Yes" and you are good to go!

Step 6: Additional Step: Wifi

Use this tutorial offered by the documentation of the Raspberry Pi. Then reboot!

Comments

mrblank5 (author)2017-06-15

is there any way to turn up the mic sensitivity? on the other alexa pi that i built with a different program i could adjust the sensitivity and i cant figure out how to do it on yours

AlessandroG2 (author)2017-06-03

Hi gavinvonk, I have an error with pulse audio during Alexa service startup, even if it says that alexa is running in all my devices. I have tested audio by command lines, and it works for listening and recording, but alexa doesn't starts. What can i do?

gavinvonk (author)AlessandroG22017-06-03

Please run systemctl status AlexaPi

gavinvonk (author)gavinvonk2017-06-03

And tell me the output

AlessandroG2 (author)gavinvonk2017-06-03

here the error

gavinvonk (author)AlessandroG22017-06-04

What microphone are you using?

Also please post the output with "-l" (letter L lowercase) tapped on to the end.

AlessandroG2 (author)gavinvonk2017-06-05

Hi gavinvonk, thank you for your reply:

This is my mic:

"Sienoc Super mini USB 2.0 Mic USB Plug for Skype Msn Video Win 7 Win8" (http://amzn.eu/deFoQCJ)

I will post the log later as soon I will be near my Pi :-)

gavinvonk (author)AlessandroG22017-06-05

Not quite sure why it would not be working...

The log might help but there are other people claiming that the microphone has worked for them for their Alexa.

mrblank5 (author)2017-06-05

i cant tell by reading it, but does this auto restart and work right after you plug it back in? ive already made one and i made an instructable but it has to be setup every time it turns off

FlyingHazard (author)2017-06-02

I hadn't thought of using PulseAudio, I have a PlayStation Eye for this purpose but it doesn't work out of the box. I'll give PA a try! Thanks!

liquidcool123 (author)2017-06-01

Great explaination!

Swansong (author)2017-06-01

That's a neat way to make your own :)