Translate from Ubuntu Linux Quick Start Guide

这些说明将帮助您在运行Ubuntu Linux 16.04 LTS的机器上快速启动和运行。对于所有其他发行版,请检查依赖项、构建选项和为通用Linux创建命令。

配置要求

该教程假定:

  • 您正在使用Ubuntu Linux 16.04 LTS
  • 你有一个麦克风
  • 你的Ubuntu装置可以通过耳机或扬声器进行音频输出

注册一个产品

按照STEP 1 Raspberry Pi原教程 注册一个产品和一个安全配置文件。在这个过程中,你将下载一个“config.json”文件到本地,本文件将用来完成sample app的配置。

提示:如果您已经有了可以用于测试的注册产品,那么您可以使用它,但是必须启用它才能与基于代码的链接(Code Based Linking ,CBL)一起使用。

这里是如何为您的设备启用 CBL的教程。

设置:

a. 第一步是确保您的计算机有最新的包列表,然后安装该列表中每个包的最新版本:

1
$  sudo apt-get update && sudo apt-get upgrade -y

b. 我们需要一个地方放所有东西,所以让我们创建一些文件夹。本指南假定所有内容都构建在{home}中,我们假定它是您的主目录。如果您选择使用不同的文件夹名称,请在本指南中相应地更新以下命令:

1
2
3
$  mkdir sdk-folder
$ cd sdk-folder
$ mkdir sdk-build sdk-source third-party application-necessities

c. 现在,让我们设置工具链(tool chain):

1
$  sudo apt-get install -y git gcc cmake openssl clang-format

d. 接下来,我们需要通过apt-get去下载一些可用的依赖:

1
$  sudo apt-get install -y openssl libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-good libgstreamer-plugins-good1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-libav pulseaudio doxygen libsqlite3-dev repo libasound2-dev

e. AVS Device SDK依赖HTTP2 与Alexa服务连接。为了满足这个需求,我们将使用nghttp2和openssl构建curl。如果您更喜欢使用mbed TLS进行构建,请单击此处获取说明:

  • 开始安装nghttp2。提示:这个命令将会下载并安装nghttp2的依赖:
1
$  sudo apt-get install -y g++ make binutils autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev libjemalloc-dev cython python3-dev python-setuptools 
  • 现在让我们从source构建nghttp2:
1
2
3
4
5
6
7
8
9
10
$  cd ~/sdk-folder/third-party
$ git clone https://github.com/tatsuhiro-t/nghttp2.git
$ cd nghttp2
$ autoreconf -i
$ automake
$ autoconf
$ cd nghttp2
$ ./configure
$ make
$ sudo make install
  • 现下载curl的最新版本,并配置支持nghttp2和openssl:
1
2
3
4
5
6
7
8
$  cd ~/sdk-folder/third-party
$ wget http://curl.haxx.se/download/curl-7.54.0.tar.bz2
$ tar -xvjf curl-7.54.0.tar.bz2
$ cd curl-7.54.0
$ ./configure --with-nghttp2=/usr/local --with-ssl
$ make
$ sudo make install
$ sudo ldconfig
  • 测试curl:
1
$  curl -I https://nghttp2.org/

如果请求成功,你将会看到如下的一条信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
HTTP/2 200
date: Fri, 15 Dec 2017 18:13:26 GMT
content-type: text/html
last-modified: Sat, 25 Nov 2017 14:02:51 GMT
etag: "5a19780b-19e1"
accept-ranges: bytes
content-length: 6625
x-backend-header-rtt: 0.001021
strict-transport-security: max-age=31536000
server: nghttpx
via: 2 nghttpx
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff

f. 需要PortAudio来记录麦克风数据。运行此命令安装和配置PortAudio:

1
2
3
4
5
$  cd ~/sdk-folder/third-party
$ wget -c http://www.portaudio.com/archives/pa_stable_v190600_20161030.tgz
$ tar zxf pa_stable_v190600_20161030.tgz
$ cd portaudio
$ ./configure --without-jack && make

g. 现在是克隆AVS Device SDK的时候了。导航到您的sdk源文件夹并运行以下命令:

1
2
$  cd ~/sdk-folder/sdk-source
$ git clone git://github.com/alexa/avs-device-sdk.git

h. 假设下载成功,下一步是构建SDK。这个命令做了一些事情:

  • 它声明PortAudio用于捕获麦克风数据,并指向它的lib路径和包含目录
  • 它声明安装了gstreamer,并将在构建SampleApp时使用它
  • 它声明唤醒字检测器处于“OFF”状态
    • 非Linux支持来自Sensory和Kitt.ai的唤醒词检测器。每一个都需要提供商的许可。有关使用唤醒字检测器进行构建的说明,请参见构建选项。

重要提示:将{home}替换为您的主目录的完整路径(不要使用~/):

1
2
3
$  cd /{home}/sdk-folder/sdk-build
$ cmake /{home}/sdk-folder/sdk-source/avs-device-sdk -DSENSORY_KEY_WORD_DETECTOR=OFF -DGSTREAMER_MEDIA_PLAYER=ON -DPORTAUDIO=ON -DPORTAUDIO_LIB_PATH=/{home}/sdk-folder/third-party/portaudio/lib/.libs/libportaudio.a -DPORTAUDIO_INCLUDE_DIR=/{home}/sdk-folder/third-party/portaudio/include
$ make

设置配置文件(avs-device-sdk/Integration/AlexaClientSDKConfig.json):

参考配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 {
"cblAuthDelegate":{
// Path to CBLAuthDelegate's database file. e.g. /home/ubuntu/Build/cblAuthDelegate.db
// Note: The directory specified must be valid.
// The database file (cblAuthDelegate.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for CBLAuthDelegate (don't use it for other components of SDK)
"databaseFilePath":"/home/patten/workspace/alexa/sdk-folder/application-necessities/cblAuthDelegate.db"
},
"deviceInfo":{
// Unique device serial number. e.g. 123456
"deviceSerialNumber":"12345678",
// The Client ID of the Product from developer.amazon.com
"clientId": "amzn1.application-oa2-client.c4d72a06*************d75948a72dd",
// Product ID from developer.amazon.com
"productId": "austin_alexa"
},
"capabilitiesDelegate":{
// The endpoint to connect in order to send device capabilities.
// This will only be used in DEBUG builds.
// e.g. "endpoint": "https://api.amazonalexa.com"
// Override the message to be sent out to the Capabilities API.
// This will only be used in DEBUG builds.
// e.g. "overridenCapabilitiesPublishMessageBody": {
// "envelopeVersion":"20160207",
// "capabilities":[
// {
// "type":"AlexaInterface",
// "interface":"Alerts",
// "version":"1.1"
// }
// ]
// }
},
"miscDatabase":{
// Path to misc database file. e.g. /home/ubuntu/Build/miscDatabase.db
// Note: The directory specified must be valid.
// The database file (miscDatabase.db) will be created by SampleApp, do not create it yourself.
"databaseFilePath":"/home/patten/workspace/alexa/sdk-folder/application-necessities/miscDatabase.db"
},
"alertsCapabilityAgent":{
// Path to Alerts database file. e.g. /home/ubuntu/Build/alerts.db
// Note: The directory specified must be valid.
// The database file (alerts.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for alerts (don't use it for other components of SDK)
"databaseFilePath":"/home/patten/workspace/alexa/sdk-folder/application-necessities/alerts.db"
},
"settings":{
// Path to Settings database file. e.g. /home/ubuntu/Build/settings.db
// Note: The directory specified must be valid.
// The database file (settings.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for settings (don't use it for other components of SDK)
"databaseFilePath":"/home/patten/workspace/alexa/sdk-folder/application-necessities/settings.db",
"defaultAVSClientSettings":{
// Default language for Alexa.
// See https://developer.amazon.com/docs/alexa-voice-service/settings.html#settingsupdated for valid values.
"locale":"en-US"
}
},
"bluetooth" : {
// Path to Bluetooth database file. e.g. /home/ubuntu/Build/bluetooth.db
// Note: The directory specified must be valid.
// The database file (bluetooth.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for bluetooth (don't use it for other components of SDK)
"databaseFilePath":""
},
"certifiedSender":{
// Path to Certified Sender database file. e.g. /home/ubuntu/Build/certifiedsender.db
// Note: The directory specified must be valid.
// The database file (certifiedsender.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for certifiedSender (don't use it for other components of SDK)
"databaseFilePath":"/home/patten/workspace/alexa/sdk-folder/application-necessities/certifiedSender.db"
},
"notifications":{
// Path to Notifications database file. e.g. /home/ubuntu/Build/notifications.db
// Note: The directory specified must be valid.
// The database file (notifications.db) will be created by SampleApp, do not create it yourself.
// The database file should only be used for notifications (don't use it for other components of SDK)
"databaseFilePath":"/home/patten/workspace/alexa/sdk-folder/application-necessities/notifications.db"
},
"sampleApp":{
// To specify if the SampleApp supports display cards.
"displayCardsSupported":true
// The firmware version of the device to send in SoftwareInfo event.
// Note: The firmware version should be a positive 32-bit integer in the range [1-2147483647].
// e.g. "firmwareVersion": 123
// The default endpoint to connect to.
// See https://developer.amazon.com/docs/alexa-voice-service/api-overview.html#endpoints for regions and values
// e.g. "endpoint": "https://avs-alexa-na.amazon.com"

// Example of specifying suggested latency in seconds when openning PortAudio stream. By default,
// when this paramater isn't specified, SampleApp calls Pa_OpenDefaultStream to use the default value.
// See http://portaudio.com/docs/v19-doxydocs/structPaStreamParameters.html for further explanation
// on this parameter.
//"portAudio":{
// "suggestedLatency": 0.150
//}
}

// Example of specifying output format and the audioSink for the gstreamer-based MediaPlayer bundled with the SDK.
// Many platforms will automatically set the output format correctly, but in some cases where the hardware requires
// a specific format and the software stack is not automatically setting it correctly, these parameters can be used
// to manually specify the output format. Supported rate/format/channels values are documented in detail here:
// https://gstreamer.freedesktop.org/documentation/design/mediatype-audio-raw.html
//
// By default the "autoaudiosink" element is used in the pipeline. This element automatically selects the best sink
// to use based on the configuration in the system. But sometimes the wrong sink is selected and that prevented sound
// from being played. A new configuration is added where the audio sink can be specified for their system.
// "gstreamerMediaPlayer":{
// "outputConversion":{
// "rate":16000,
// "format":"S16LE",
// "channels":1
// },
// "audioSink":"autoaudiosink"
// },

// Example of specifiying curl options that is different from the default values used by libcurl.
// "libcurlUtils":{
//
// By default libcurl is built with paths to a CA bundle and a directory containing CA certificates. You can
// direct the AVS Device SDK to configure libcurl to use an additional path to directories containing CA
// certificates via the CURLOPT_CAPATH setting. Additional details of this curl option can be found in:
// https://curl.haxx.se/libcurl/c/CURLOPT_CAPATH.html
// "CURLOPT_CAPATH":"INSERT_YOUR_CA_CERTIFICATE_PATH_HERE",
//
// You can specify the AVS Device SDK to use a specific outgoing network interface. More information of
// this curl option can be found here:
// https://curl.haxx.se/libcurl/c/CURLOPT_INTERFACE.html
// "CURLOPT_INTERFACE":"INSERT_YOUR_INTERFACE_HERE"
// },

// Example of specifying a default log level for all ModuleLoggers. If not specified, ModuleLoggers get
// their log level from the sink logger.
// "logging":{
// "logLevel":"INFO"
// },

// Example of overriding a specific ModuleLogger's log level whether it was specified by the default value
// provided by the logging.logLevel value (as in the above example) or the log level of the sink logger.
// "acl":{
// "logLevel":"DEBUG9"
// }
}


// Notes for logging
// The log levels are supported to debug when SampleApp is not working as expected.
// There are 14 levels of logging with DEBUG9 providing the highest level of logging and CRITICAL providing
// the lowest level of logging i.e. if DEBUG9 is specified while running the SampleApp, all the logs at DEBUG9 and
// below are displayed, whereas if CRITICAL is specified, only logs of CRITICAL are displayed.
// The 14 levels are:
// DEBUG9, DEBUG8, DEBUG7, DEBUG6, DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, DEBUG0, INFO, WARN, ERROR, CRITICAL.

// To selectively see the logging for a particular module, you can specify logging level in this json file.
// Some examples are:
// To only see logs of level INFO and below for ACL and MediaPlayer modules,
// - grep for ACSDK_LOG_MODULE in source folder. Find the log module for ACL and MediaPlayer.
// - Put the following in json:

// "acl":{
// "logLevel":"INFO"
// },
// "mediaPlayer":{
// "logLevel":"INFO"
// }

// To enable DEBUG, build with cmake option -DCMAKE_BUILD_TYPE=DEBUG. By default it is built with RELEASE build.
// And run the SampleApp similar to the following command.
// e.g. ./SampleApp /home/ubuntu/.../AlexaClientSDKConfig.json /home/ubuntu/KittAiModels/ DEBUG9"

运行并授权:

导航到您的构建文件夹(~/sdk-folder/sdk-build),然后:
a. 启动示例应用程序:

1
$  ./SampleApp/src/SampleApp Integration/AlexaClientSDKConfig.json

b. 等待示例应用程序显示如下消息:

1
2
3
4
5
6
##################################
# NOT YET AUTHORIZED #
##################################
################################################################################################
# To authorize, browse to: 'https://amazon.com/us/code' and enter the code: {XXXX} #
################################################################################################

c. 使用浏览器导航到来自示例应用程序的消息中指定的URL(此处为https://amazon.com/us/code)。
d. 如果需要这样做,请使用Amazon用户凭证进行身份验证。
e. 输入来自示例应用程序的消息中指定的代码。
f. 选择“Allow”。
g. 等待CBLAuthDelegate从Amazon (LWA)登录成功获取访问令牌和刷新令牌。此时,示例应用程序将打印如下消息:

1
2
3
########################################
# Alexa is currently idle! #
########################################

h. 您现在可以使用样例应用程序了。下一次启动样例应用程序时,您不需要进行授权过程。

更多细节:

  • 如果您通过“k”命令退出示例应用程序,CBLAuthDelegate数据库将被清除,您需要重新授权您的客户机。
  • 如果您想将此授权移动到另一个示例应用程序安装,则需要在AlexaClientSDKConfig.json中复制deviceInfo对象到新安装的应用程序。您还需要复制文件“/{home}/sdk-folder/application- necessary /cblAuthDelegate”到新的安装,并更新新安装中的AlexaClientSDKConfig.json,以便cblAuthDelegate的databaseFilePath属性指向它。