Alexa客户端在您的浏览器中。Django应用程序
alexa-browser-client的Python项目详细描述
Alexa Browser客户端
Alexa客户端在您的浏览器中Django应用程序从桌面、手机或平板电脑浏览器与Alexa通话。
演示
演示应该真的被听到了,所以点击下面的gif在youtube上查看它。
运行演示
首先执行以下步骤:
$ git clone git@github.com:richtier/alexa-browser-client.git $ cd alexa-browser-client $ virtualenv .venv -p python3.6 &&source .venv/bin/activate && make test_requirements
- Compile snowboy
$ make demo
- 转到http://localhost:8000观看基本演示,或http://localhost:8000/mixer/播放响应音频
安装
pip install alexa_browser_client
确保设置INSTALLED_APPS
至少包含以下条目:
INSTALLED_APPS = [
'django.contrib.staticfiles',
'channels',
'alexa_browser_client',
]
依赖关系
Snowboy检测何时发出尾迹词“alexa”。
必须手动编译Snowboy。将编译后的snowboy
文件夹复制到项目的顶层默认情况下,文件夹结构应为:
.
├── ...
├── snowboy
| ├── snowboy-detect-swig.cc
| ├── snowboydetect.py
| └── resources
| ├── alexa.umdl
| └── common.res
└── ...
如果默认的文件夹结构不适合您的需要,您可以customize the wakeword detector。
路由和url
将url(r'^', include('alexa_browser_client.config.urls')),
添加到urls.py
url_patterns
。
将include('alexa_browser_client.config.routing.channel_routing')
添加到routing.py
channel_routing
中。
身份验证
此应用程序使用Alexa语音服务。要使用avs,首先必须有一个developer account。然后注册产品here在“您的产品是应用程序还是设备”下选择“应用程序”?
确保更新设置。py:
Setting | Notes |
---|---|
^{ | Retrieve by clicking on the your product listed here |
^{ | Retrieve by clicking on the your product listed here |
^{ | Retrieve by reading "Product ID" here |
刷新令牌
您需要通过网络浏览器登录到Amazon以获取刷新令牌
要启用此功能,请转到here,然后单击您的产品在Security Profile
下设置一些安全设置,并假设您在localhost:8000上运行,设置以下内容:
setting | value |
---|---|
Allowed Origins | https://localhost:8000/refreshtoken/ |
Allowed Return URLs | https://localhost:8000/refreshtoken/callback/ |
用法
配置完所有设置后:
- 运行django:
./manage.py runserver
- 转到
http://localhost:8000
开始与Alexa交谈
定制
唤醒字
默认的wakeword是“alexa”。您可以通过自定义生命周期的audio_detector_class
:
# my_project/consumers.pyimportalexa_browser_clientimportcommand_lifecycleclassCustomAudioDetector(command_lifecycle.wakeword.SnowboyWakewordDetector):wakeword_library_import_path='dotted.import.path.to.wakeword.Detector'resource_file=b'path/to/resource_file.res'decoder_model=b'path/to/model_file.umdl'classCustomAudioLifecycle(alexa_browser_client.AudioLifecycle):audio_detector_class=CustomAudioDetectorclassCustomAlexaConsumer(alexa_browser_client.AlexaConsumer):audio_lifecycle_class=CustomAudioLifecycle
然后在你的routing.py
:
import alexa_browser_client.consumers
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.sessions import SessionMiddlewareStack
from django.conf.urls import url
application = ProtocolTypeRouter({
'websocket': SessionMiddlewareStack(
URLRouter([
url(r"^ws/$", alexa_browser_client.consumers.AlexaConsumer),
])
),
})
版本控制
我们使用SemVer进行版本控制有关可用的版本,请参见PyPI
其他项目
这个项目使用Voice Command Lifecycle和Alexa Voice Service Client。