Build a DIY Amazon's Alexa With a Raspberry Pi and a MATRIX Creator

35,350

75

25

Posted

Introduction: Build a DIY Amazon's Alexa With a Raspberry Pi and a MATRIX Creator

This tutorial will help you build your own Amazon's Alexa using a Raspberry Pi and MATRIX Creator, the first Microphone Array add-on for Raspberry Pi.

We will use Alexa Voice Services (AVS), it is the service used by Amazon Echo that allows us to accomplish many of the challenging tasks in this project.

Step 1: Parts That You'll Need

  1. MATRIX Creator.
  2. Raspberry Pi 2 or 3
  3. 5V 2.0A Power Supply
  4. Speaker (Needs Aux input.)

Step 2: MATRIX Creator MEMS Microphones

MATRIX Creator has 8 MP34DB02 MEMS audio sensor omnidirectional microphones.

  • Low power consumption
  • 120 dBSPL acoustic overload point
  • 62.6 dB signal-to-noise ratio
  • Omnidirectional sensitivity
  • –26 dBFS sensitivity

Step 3: Setting Up the Software (This Is From GitHub Quickstart)

Welcome to the MATRIX Creator! To enjoy your new board you’ll need to set it up. First, you need to have Raspbian installed on your Raspberry Pi. If you don’t have it, you can download it and follow the instructions.

Then you need to install the software that will allow you to program the MATRIX Creator. To do it, you need to configure APT. The following steps should do it:

echo "deb http:packages.matrix.one/matrix-creator/ ./" | sudo tee --append /etc/apt/sources.list 

Now update the package list.

sudo apt-get update 

Then you can install the required packages.

sudo apt-get install matrix-creator-init cmake g++ git 

Now reboot the Raspberry Pi. After rebooting, the FPGA and SAM3 MCU will be programmed automatically. That is, after every reboot the FPGA will have the default firmware.

If you wish, you can also learn more about other features of MATRIX Creator on GithubQuestions? Post them on raspberrypi.stackexchange.com! Use the tag #matrix-creator.

Step 4: Set Alexa Voice Service (AVS) - Alexa - 1

Go to Alexa Voice Service (AVS) website and create a new developer account.

  • Create an account using your email and fill in the form with your personal information. You will be asked to agree; accept in order to use AVS.
  • You will then be asked about monetization. We don't earn money with this so select “No” for both options.
  • Once you complete the registration process, it’s time to configure AVS.

Step 5: Set Alexa Voice Service (AVS) - Alexa - 2

In the main page of AVS dashboard, go to ALEXA.

Then click on “Get Started” under the “Alexa Voice Service” section.

A simple list with available devices will then be displayed. Let's start by creating a new device.

Step 6: Set Alexa Voice Service (AVS) - Alexa - 3

Under Device Type ID choose a name for your device and Display Name

Then in the security profile you need to select the device, each device has a unique profile. So select your device and it show a some important information:

So copy Security Profile Description, Security Profile ID, Client ID and Client secret. Keep this information private it's only for your device. And keep this information it's important in next steps.

Step 7: Set Alexa Voice Service (AVS) - Alexa - 4

Configure the type of device, in this case select Home appliance. Fill in all forms and continue with the process.

Next you will be asked about Amazon Music; we recommend not enabling this feature yet. Finally, submit the configuration.

Your device should now be listed in the dashboard. Now we need to configure more technical details to set up with Raspberry Pi.

Step 8: Set Host Name in Raspberry Pi - 1

It's necessary to configure some things in Raspberry Pi so let's start.

In the command line:

sudo raspi-config

You will see a menu option.

Go to Advanced options and select Hostname.

Set your own HOST_NAME. It’s an important configuration, so keep that in mind.

Step 9: Set Alexa Voice Service (AVS) - Alexa - 5

Go back into AVS configuration and we need to set other configurations. So press Edit Button.

Here you find all device configuration, there go to Web Setting an edit it.

It show a page . Set:

Allowed Origins: http://HOST_NAME.local:5000
Allowed Return URLs: http://HOST_NAME.local:5000/code

So save this configurations.

Step 10: Configure MATRIX Creator HAL

Now it's necessary to clone MATRIX Creator HAL.

git clone https://github.com/matrix-io/matrix-creator-hal.git
cd matrix-creator-hal
mkdir build
cd build
cmake ../
make
sudo make install

The HAL libraries are now installed on your Raspberry Pi.

Step 11: Configure MATRIX Creator Alexa Demo - 1

Now clone GitHub source code with:

git clone https://github.com/matrix-io/matrix-creator-alexa-voice-demo.git

Then go to following directory and install the following software:

cd matrix-creator-alexa-voice-demo 
sudo apt-get update
sudo apt-get install  memcached python-pip mpg123

Then run the next command:

sudo pip install -r requirements.txt

Now edit creds.py

ProductID = "PRODUCT_ID"
Security_Profile_Description = "SECURITY_PROFILE_DESCRIPTION"
Security_Profile_ID = "SECURITY_PROFILE_ID"
Client_ID = "CLIENT_ID"Client_Secret = ""

This information was also in Step 6.

Step 12: Configure MATRIX Creator Alexa Demo - 2

So now run the auth_web.py with:

./auth_web.py &
[12/Aug/2016:00:41:16] ENGINE Listening for SIGTERM.
[12/Aug/2016:00:41:16] ENGINE Listening for SIGUSR1.
[12/Aug/2016:00:41:16] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.[12/Aug/2016:00:41:16] ENGINE Started monitor thread 'Autoreloader'.
[12/Aug/2016:00:41:16] ENGINE Started monitor thread '_TimeoutMonitor'.
[12/Aug/2016:00:41:16] ENGINE Serving on http://0.0.0.0:5000
[12/Aug/2016:00:41:16] ENGINE Bus STARTED

Step 13: Configure MATRIX Creator Alexa Demo - 3

It's necessary to compile the microphone software at this point, so go to the micarray directory.

cd micarray
mkdir build
cd build
cmake ../
make

That is the compilation process for the microphone software.

Now you have all software configurations on your Raspberry Pi.

Step 14: Browser Confirmation

Make sure your Raspberry Pi is connected to your local network, open a web browser, and go to this address:

http://HOST_NAME.local:5000

You will see an Amazon page as shown above.

Step 15: Run Alexa With Raspberry and MATRIX Creator

Return to the Raspberry, go to the matrix-creator-alexa-voice-demo folder, and run:

./alexa_voice_demo.py

You did it! You’ve created your very own Amazon Alexa with a Raspberry Pi and a MATRIX Creator.

Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    23 Comments

    I am trying to build a DIY Amazon's Alexa with a raspberry pi 3 and matrix creator and I followed the instructions on this website along with this website - https://github.com/matrix-io/matrix-creator-alexa-...

    However, with step 13 in order to compile the microphone software I am required to go to the micarray directory by using '' cd midcarray'', it failed to locate file

    help me: i'm work finish but matrix creator not work? why?

    INFO: *** THREAD JOINING: Sensory ***
    ERROR:An error happened in the mainLoop of SensoryWakeWord snsrRun(): task.fex: Operation failed.
    INFO:SensoryWakeWordEngine: mainLoop thread ended
    INFO:WakeWordAgent: State set to WAKE_WORD_PAUSED(6)
    INFO:WakeWordAgent: IPC Command received:4
    INFO:WakeWordAgent: State set to WAKE_WORD_RESUME_REQUESTED(7)
    INFO:SensoryWakeWordEngine: handling resume
    INFO:SensoryWakeWordEngine: mainLoop thread started
    INFO:WakeWordAgent: State set to IDLE(2)
    INFO:===> WakeWordAgent: wake word detected <===

    i cannot find the micarray directory, may i know why?

    can anyone help me with this error?

    I headed over to the new build and all worked GREAT!! I posted a quick video and a couple of pics.

    Having issue as well

    rmmod: ERROR: Module lirc_rpi is not currently loaded

    NameError: global name 'refresh_token' is not defined


    Raspberry Pi 3 B, Clean Image from scratch

    This fixed it for me...

    https://github.com/sammachin/AlexaPi/issues/58