Alexa客户端在您的浏览器中。Django应用程序

alexa-browser-client的Python项目详细描述


Alexa Browser客户端

code-climate-imagecircle-ci-imagecodecov-imagepypi-imagedjango-version-image

Alexa客户端在您的浏览器中Django应用程序从桌面、手机或平板电脑浏览器与Alexa通话。


演示

演示应该真的被听到了,所以点击下面的gif在youtube上查看它。

Demo

运行演示

首先执行以下步骤:

  1. Configure your Amazon oauth configuration
  2. Set your environment variables
  3. 安装:
$ 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
  1. Compile snowboy
  2. $ make demo
  3. 转到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.pyurl_patterns

include('alexa_browser_client.config.routing.channel_routing')添加到routing.pychannel_routing中。

身份验证

此应用程序使用Alexa语音服务。要使用avs,首先必须有一个developer account。然后注册产品here在“您的产品是应用程序还是设备”下选择“应用程序”?

确保更新设置。py:

SettingNotes
^{}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上运行,设置以下内容:

settingvalue
Allowed Originshttps://localhost:8000/refreshtoken/
Allowed Return URLshttps://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 LifecycleAlexa Voice Service Client

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Kafka DSL Kstream>Ktable连接序列化编译错误   java为什么Bean A中的参数注入会破坏属性解析Bean B?(都是类型PropertyPlaceHolderConfigure的类型)   java Oracle SQL开发人员在尝试导出数据时调用TargetException   编辑JTree中返回的java意外值   Java,Lambda:如何从不同类型的列表集合中查找列表?   如何使用java执行命令   java如何将drawable分配给widgets按钮   JavaIntelliJ13JSF对Springbeans的支持   java转换。转换成补语   java Tomcat的性能测试   sendmail Java发送邮件函数   java重用ProjectReactor/Flux/Mono被认为是最佳实践吗?   javafx在Java中错误地转换为lambda表达式   反序列化json数组,其中属性值为数组java   java After ItemClickListener调用方法   此Java代码中有多少对象符合垃圾收集条件?   java程序“keytool”可以在以下包中找到