Voice assistants and smart speakers are getting to be very popular nowadays. Probably, you want to buy one, but firstly want to try it, or even create yours?
In this article I’ll show how to install Amazon Alexa on Gentoo system. You can use your laptop for example, it already has built-in microphone and speakers.

This howto is based on these references from Amazon and KITT.ai:
https://github.com/alexa/avs-device-sdk/wiki/Linux-Reference-Guide
https://github.com/Kitt-AI/snowboy/

Let’s go!

Preparations

What we will need:
– Linux-based laptop or desktop with microphone/speakers. I’ve using Gentoo-based amd64 machine, but, I guess, with other Linux distros you’ll be ok also.
– Some time and patience.

First, let’s install dependencies:

Add this to your /etc/portage/package.use/01_local file:

=net-misc/curl-7.65.0 http2
=sci-libs/atlas-3.10.2 static-libs  generic
=sci-libs/clblas-2.10 performance
=sci-libs/hdf5-1.10.5 -threads
#emerge -av curl gst-plugins-base gst-plugins-good gst-plugins-ugly gst-plugins-mpg123 sci-libs/atlas sci-libs/cblas-reference virtual/blas virtual/cblas

Next, let’s clone AVS(amazon voice services) SDK :

#mkdir ~/alexa-test
#cd ~/alexa-test
#mkdir build source third-party application-necessities
#cd ./source
#git clone https://github.com/alexa/avs-device-sdk.git

Then, we need to install third-party dependencies:

#cd ./third-party/
#wget -c http://www.portaudio.com/archives/pa_stable_v190600_20161030.tgz
#tar zxf ./pa_stable_v190600_20161030.tgz
#cd ./portaudio/

Here I’am using default configuration options. If you’ll have some problems with running Alexa, you can try to enable debug flags in portaudio (check configure –help output).

#./configure --without-jack
#make
#cd ../

Next, clone Snowboy – it is a keyword detector engine, a thing that will wake Alexa when you’ll say “Alexa”:

#git clone https://github.com/Kitt-AI/snowboy.git
#cd ..

Configure and build SDK

Now, we can start configuration of SDK (please double-check all paths!):

#export RELPATH=~/alexa-test
#cmake $RELPATH/source/avs-device-sdk \
-DGSTREAMER_MEDIA_PLAYER=ON \
-DPORTAUDIO=ON \
-DPORTAUDIO_LIB_PATH=$RELPATH/third-party/portaudio/lib/.libs/libportaudio.a \
-DPORTAUDIO_INCLUDE_DIR=$RELPATH/third-party/portaudio/include \
-DKITTAI_KEY_WORD_DETECTOR=ON \
-DKITTAI_KEY_WORD_DETECTOR_LIB_PATH=$RELPATH/third-party/snowboy/lib/ubuntu64/libsnowboy-detect.a \
-DKITTAI_KEY_WORD_DETECTOR_INCLUDE_DIR=$RELPATH/third-party/snowboy/include \
-DCMAKE_BUILD_TYPE=DEBUG

At this point, SDK is configured and almost ready to build. But, unfortunately, at Gentoo linux you’ll get linking errors like “undefined reference … ” even with required libraries installed in system. To fix this, run:

#find -name link.txt | xargs sed -i 's/-lblas/-lblas -lcblas/'

And now, you can start build:

#make -j2

Configure your Alexa

If build is finished without errors – you’re almost there! Now we need to make configuration file for our Alexa app, and connect it to Amazon cloud.

Please follow this instruction and download config.json file: https://github.com/alexa/avs-device-sdk/wiki/Create-Security-Profile

When you have config.json, do next steps:

#mkdir ~/alexa-test/build/Integration/database
#cd ~/alexa-test/source/avs-device-sdk/tools/Install
#export RELPATH=~/alexa-test
#cp ~/Downloads/config.json ./
#bash genConfig.sh config.json device_serial_number \
$RELPATH/build/Integration/database \
$RELPATH/source/avs-device-sdk \
$RELPATH/build/Integration/AlexaClientSDKConfig.json

Now, let’s prepare our keyword detector:

#cp ../third-party/snowboy/resources/alexa/alexa-avs-sample-app/alexa.umdl ../third-party/snowboy/resources/

Start your Alexa!

And try to run our app:

#./SampleApp/src/SampleApp ./Integration/AlexaClientSDKConfig.json  ../third-party/snowboy/resources/



If all goes good, you’ll see message “NOT YET AUTHORIZED”, and authorization code. Go to https://amazon.com/us/code, enter that code, and now you should have fully working Alexa on your PC!

If SampleApp will throw some errors at initialization, you can append “DEBUG9” to starting command line – in this case, there will be lots of debug input. And, if you’re having errors with sound devices – try to start application under root.

I’d like to say thanks to Nikolay Merinov for helping me with some aspects of this howto.