Raspberry Pi 3 模擬(實作) Amazon echo - Linux

Puput avatar
By Puput
at 2017-10-16T11:19

Table of Contents

Raspberry Pi 3 模擬(實作) Amazon echo

(註)本篇較不適合樹莓派新手

公司說要開發類似echo家電產品 可以聲控 不要再用按鍵才會執行

經過三四天的努力 搞出來柳 避免大家走歪路 浪費寶貴的時間

一開始懵懵懂懂 不知從何下手

公司是有買了一支echo 但是看到還耍用手機(美國google store下載App)登錄才能用
在台灣不行用齁 而且還要綁定信用卡
就有點想打退堂鼓了

還好查網路可以用RPI實作 想想也是 沒魚蝦也好 就試試看囉

先從YouTube入手
看了三四個肥宅的影片 跟真的一樣 隨便一倆下子就搞定了

可偶照著操作 step by step Alexa就是沒反應

自信心大受打擊 如此用掉了兩天

只停留在可以放音樂/錄音階段

歸納幾個問題點
1. RPI 版本 2 or 3
2. 硬體音效設定
3. Amazon Developer Account 設定
(為避免愈描愈黑 就不再詳述錯誤或模稜兩可情形)

找不到錯誤原因 也找不到正解
只好再想別的方法

其中Amazon 有提供一個網頁版的模擬Echo給人測試
結果喊破了喉嚨 也沒人理

通常這個時候 依照慣例 都是往大陸求教 他棉人多資源也多 好辦事
可是好死不死 這個案子必須要同時上Amazon網站 取得權仗 才能用
加上也許太愛國了 他們也有自取的語音辨識cloud
結果就是只有少數一些舊資料 沒啥路用

Alexa不行 換Jasper好了

網路找到一些文章 "即時口譯機器人DIY" "宇宙翻譯機"...
按圖施工 也是搞了兩天 無動於衷
自信心即將直達谷底

過了一個風雨的週末
從頭來過 才找這篇正解

https://www.raspberrypi.org/blog/amazon-echo-homebrew-version/

Want to build your own? Here’s a video guide to setting the beast up from
Novaspirit

Tech. You can also find everything you need on Amazon’s GitHub.

________________________________________
https://github.com/alexa/alexa-avs-sample-app

About the project

This project provides a step-by-step walkthrough to help you build a
hands-free Alexa

Voice Service (AVS) prototype in 60 minutes, using wake word engines from
Sensory or

KITT.AI. Now, in addition to pushing a button to "start listening", you can
now also

just say the wake word "Alexa", much like the Amazon Echo. You can find
step-by-step

instructions to set up the hands-free prototype on Raspberry Pi, or follow
the

instructions to set up the push-to-talk only prototype on Linux, Mac, or
Windows.

________________________________________
https://github.com/alexa/alexa-avs-sample-app/wiki/Raspberry-Pi

On this page
‧ Overview
‧ Required Hardware
‧ Step-by-step Guide
‧ Extra Credit (Setup SSH & VNC)
________________________________________
Overview

This guide provides step-by-step instructions for setting up AVS on a
Raspberry Pi. It

demonstrates how to access and test AVS using our Java sample app (running on
a

Raspberry Pi), a Node.js server, and a third-party wake word engine. You will
use the

Node.js server to obtain a Login with Amazon (LWA) authorization code by
visiting a

website using your Raspberry Pi’s web browser.
For instructions on how to set it up on Mac, Linux or Windows, please see our
wiki.
________________________________________
Required hardware
Before you get started, let’s review what you’ll need.
1. Raspberry Pi 3 (Recommended) or Pi 2 Model B (Supported) - Buy at Amazon -
Pi

3 or Pi 2.
2. Micro-USB power cable for Raspberry Pi.
3. Micro SD Card (Minimum 8 GB) - You need an operating system to get
started.

NOOBS (New Out of the Box Software) is an easy-to-use operating system
install manager

for Raspberry Pi. The simplest way to get NOOBS is to buy an SD card with
NOOBS pre-

installed - Raspberry Pi 8GB Preloaded (NOOBS) Micro SD Card. Alternatively,
you can

download and install it on your SD card (follow instructions here).
4. USB 2.0 Mini Microphone - Raspberry Pi does not have a built-in
microphone; to

interact with Alexa you’ll need an external one to plug in - Buy on Amazon
5. External Speaker with 3.5mm audio cable - Buy on Amazon
6. A USB Keyboard & Mouse, and an external HDMI Monitor - we also recommend

having a USB keyboard and mouse as well as an HDMI monitor handy if you’re
unable to

remote(SSH)into your Pi.
7. Internet connection (Ethernet or WiFi)
8. (Optional) WiFi Wireless Adapter for Pi 2 (Buy on Amazon). Note: Pi 3 has

built-in WiFi.

For extra credit, we’ll show you how to remote(SSH) into your device,
eliminating the

need for a monitor, keyboard and mouse - and how to tail logs for
troubleshooting.
________________________________________

Let’s get started
The original Alexa on a Pi project required manual download of
libraries/dependencies

and updating a series of configuration files that were prone to human error.
To make

the process faster and easier, we’ve included an install script with the
project that

will take care of all the heavy lifting. Not only does this reduce setup time
to less

than an hour on a Raspberry Pi 3, it only requires developers to adjust three


variables in a single install script -

________________________________________
Step 1: Setting up your Pi
Unless you already have Raspbian Stretch or Jessie installed on your Pi,
please follow

our guide - Setting up the Raspberry Pi - that will walk you through
downloading and

installing Raspbian, and connecting the hardware (if you’re unfamiliar with
Raspberry

Pi, we highly recommend you follow the guide above to get your Pi up and
ready before

moving further).

________________________________________
Step 2: Register for an Amazon developer account
Unless you already have one, go ahead and create a free developer account at

developer.amazon.com. You should review the AVS Terms and Agreements here.

________________________________________
Step 3: Create a device and security profile
Follow the steps here to register your product and create a security profile.
Make note of the following parameters. You’ll need these in Step 5 below.
财 ProductID (also known as Device Type ID),
财 ClientID, and
财 ClientSecret
Important: Make sure your Allowed Origins and Allowed Return URLs are set
under

Security Profile > Web Settings (see Create a device and security profile):

‧ Allowed Origins: https://localhost:3000
‧ Allowed Return URLs: https://localhost:3000/authresponse
________________________________________
Step 4: Clone the sample app
Open terminal, and type the following:
cd Desktop
git clone https://github.com/alexa/alexa-avs-sample-app.git
________________________________________
Step 5: Update the install script with your credentials
Before you run the install script, you need to update the script with the
credentials

that you got in step 3 - ProductID, ClientID, ClientSecret. Type the
following in

terminal:
cd ~/Desktop/alexa-avs-sample-app
nano automated_install.sh

Paste the values for ProductID, ClientID, and ClientSecret that you got from
Step 3

above.
The changes should look like this:
财 ProductID=”RaspberryPi3”
财 ClientID=”amzn.xxxxx.xxxxxxxxx”
财 ClientSecret=”4e8cb14xxxxxxxxxxxxxxxxxxxxxxxxxxxxx6b4f9”
Type ctrl-X and then Y, and then press Enter to save the changes to the file.
________________________________________
Step 6: Run the install script
You are now ready to run the install script. This will install all
dependencies,

including the two wake word engines from Sensory and KITT.AI.
Note: The install script will install all project files in the folder that
the script

is run from.
To run the script, open terminal and navigate to the folder where the project
was

cloned. Then run the following command:
cd ~/Desktop/alexa-avs-sample-app
. automated_install.sh
You’ll be prompted to answer a few simple questions. These help to ensure
that

you’ve completed all necessary prerequisites before continuing.

When the wizard starts, go grab a cup of coffee - it takes about 30 minutes.
________________________________________
Step 7: Run your web service, sample app and wake word engine
Now that installation is complete, you’ll need to run three commands in 3
separate

terminal windows:
1. Terminal Window 1: to run the web service for authorization
2. Terminal Window 2: to run the sample app to communicate with AVS
3. Terminal Window 3: to run the wake word engine which allows you to start
an

interaction using the phrase “Alexa”.
Note: These commands must be run in order.
Terminal Window 1
Open a new terminal window and type the following commands to bring up the
web service

which is used to authorize your sample app with AVS:
cd ~/Desktop/alexa-avs-sample-app/samples
cd companionService && npm start

The server is now running on port 3000 and you are ready to start the client.
See API Overview > Authorization to learn more about authorization.
________________________________________
Terminal Window 2
Open a new terminal window and type the following commands to run the sample
app,

which communicates with AVS:
cd ~/Desktop/alexa-avs-sample-app/samples
cd javaclient && mvn exec:exec

See API Overview > Interfaces to learn more about the messages sent to/from
AVS.
Let’s walk through the next few steps relevant to Window 2.
1. When you run the client, a window should pop up with a message that says -
Please register your device by visiting the following URL in a web browser
and

following the instructions:
https://localhost:3000/provision/d340f629bd685deeff28a917.

Would you like to open the URL automatically in your default browser?

Click on “Yes” to open the URL in your default browser.
2. If you’re running Raspbian with Pixel desktop (and with Chromium
browser),

you may get a warning from the browser. You can get around it by clicking on
Advanced

-> Proceed to localhost(unsafe).

3. You’ll be taken to a Login with Amazon web page. Enter your Amazon

credentials.

4. You’ll be taken to a Dev Authorization page, confirming that you’d like
your

device to access the Security Profile created earlier.

Click Okay.
5. You will now be redirected to a URL beginning with

https://localhost:3000/authresponsefollowed by a query string. The body of
the web

page will say device tokens ready.

6. Return to the Java application and click the OK button. The client is now

ready to accept Alexa requests.


________________________________________
Terminal Window 3
Note: Skip this step to run the same app without a wake word engine.
This project supports two third-party wake word engines: Sensory’s
TrulyHandsFree and

KITT.AI’s Snowboy. The -e parameter is used to select the agent and supports
two

values for {{engine}}: kitt_ai and sensory.
Open a new terminal window and use the following commands to bring up a wake
word

engine from Sensory or KITT.AI. The wake word engine will allow you to
initiate

interactions using the phrase “Alexa”.

To use the Sensory wake word engine, type -
cd ~/Desktop/alexa-avs-sample-app/samples
cd wakeWordAgent/src && ./wakeWordAgent -e sensory

or, type this to use KITT.AI’s wake word engine -
cd ~/Desktop/alexa-avs-sample-app/samples
cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai

Now you have a working hands-free AVS prototype!
Use the following resources to learn more about available wake word engines:
‧ Sensory
‧ KITT.AI
________________________________________
Step 8: Talk to Alexa
You can now talk to Alexa by simply using the wake word “Alexa”. Try the
following -
Say “Alexa”, then wait for the beep. Now say “what’s the time?”
Say “Alexa”, then wait for the beep. Now say “what’s the weather in
Seattle?”
If you prefer, you can also click on the “Listen” button, instead of using
the wake

word. Click once on the “Listen” button, after releasing the click, wait
for the

audio cue before beginning to speak. It may take a second or two before you
hear the

audio cue.
________________________________________
Step 9: How to Log Out of the Sample App
See Sample App Log Out Instructions.

Sample App Log Out Instructions
Known Issue
To log out of the AVS java sample app you must clear your sessionId in

/samples/javaclient/config.json, and delete your refresh_tokens file in the

/samples/companionService folder. Otherwise, the sample app will authenticate
on each

reboot.
Solution
Follow these instructions to log out of the AVS java sample app:
1. Quit the AVS java sample app (CTRL + C).
2. Open /samples/javaclient/config.json and clear your sessionId. It should
look

like this:
3. "sessionId": ""
4. Delete the refresh_tokens file in samples/companionService.
The next time you log in you will be prompted to authenticate.
________________________________________
Step 10: (Optional): Go headless and get rid of the monitor, keyboard, and
mouse
Now that you’ve got your AVS prototype running, you may want to get rid of
the

monitor, keyboard and mouse. You can do that by using SSH and VNC. Follow the


instructions to setup SSH and VNC.


2017.10.17 增加
強國文可參考這篇
https://zombiesyard.cn/2017/10/02/

--
Tags: Linux

All Comments

James avatar
By James
at 2017-10-18T12:20
好像很好玩XD 謝謝分享
Bethany avatar
By Bethany
at 2017-10-23T10:34
看不懂新幫你推QQ
John avatar
By John
at 2017-10-27T00:21
ninja
Frederic avatar
By Frederic
at 2017-10-27T12:11
似乎很好玩 不知道會不會很難操作..
Kama avatar
By Kama
at 2017-10-29T18:56
不過還要按個按鈕才能呼叫,有點雞肋...Amazon也很精啊
Liam avatar
By Liam
at 2017-10-30T09:51
不過 如果google mini能在台灣買到 應該也不用自己刻了
Olivia avatar
By Olivia
at 2017-11-01T22:44
還是原po想開發中文支援? XD
Wallis avatar
By Wallis
at 2017-11-03T18:00
mycroft也不錯玩喔!還有gnome套件可以裝
Candice avatar
By Candice
at 2017-11-03T21:00
推一個~~~

閃變成門的字型問題

Frederic avatar
By Frederic
at 2017-10-16T10:29
系統是debian 9 字型試過文全譯正黑、droid sans都有這問題 閃下面的人全部都不見了,不管是bbs還是網頁都一樣,每次看到門都要猜是閃還是門 不過我換日文字型就正常了,這篇就是換用日文字型打的... 有人有遇過嗎? - ...

clear->cls 指令修改,該去哪裡建議?

Ivy avatar
By Ivy
at 2017-10-16T00:18
這件事情終於有時間做個了結了,雖然說版上大大們幾乎都是強力勸退, 經過推文的洗禮我也曾被動搖,不過也有某位大大說想看看發出 feature request 之後的回應會是如何,於是我還是硬著頭皮寄了,然後一天內就獲得兩位重量級的回覆。 先說結論,兩位都是不支持增加 alias 的,原因幾乎都是版上大大所 ...

synergy 忽然無法開啟

Tom avatar
By Tom
at 2017-10-14T15:07
由於我還是有在windows上面文書的需求 所以一般來說我都是使用symergy共用鼠鍵 但是今天開機後synergy卻無法使用 發出錯誤訊息 未能成功執行 /usr/bin/synergys 儘管檔案存在,請檢查執行程序權限設定 但是我在terminal 中輸入 sudo synergy 也無法正常開始 所 ...

find 和 cp 的用法

Freda avatar
By Freda
at 2017-10-13T17:24
小弟有個弱弱的問題想問一下 有點不太懂這字串的用法有什麼分別 就是 我有兩個使用者 student (初始化就創的) 和 qoo123(後來創的) mkdir /root/ccc find /home -user student -type f -exec cp {} /root/c ...

抓不到Linux

Sandy avatar
By Sandy
at 2017-10-12T22:32
(已爬文) 各位大大好 剛剛在桌機上裝了ubuntu幾次 可是開機都讀不到 (按f12進入boot都只有windows或隨身碟開機) 目前安裝到一半卡掉進Linux,畫面如下圖 https://i.imgur.com/GWe9sJm.jpg 和之前用筆電的差別,終端機上沒有帳戶名,然後左邊多了一堆磁碟 事前 ...