亚历山大之声服务蟒蛇
avs的Python项目详细描述
Python Alexa语音服务应用程序
功能
- 支持Alexa语音服务API V20160207
- 支持多个音频播放器:GStreamer 1.0、MPV和MPG123
- 支持Baidu DuerOS
选项
播放器
我们有3个玩家(
mpv
,mpg123
和gstreamer)可以使用。SpeechSynthesizer
和Alerts
更喜欢mpg123
这是更灵敏的。AudioPlayer
喜欢gstreamer>;mpv
>;mpg123
。gstreamer支持更多的音频格式,在覆盆子pi上运行良好。我们还可以使用环境变量PLAYER
指定AudioPlayer
的播放器。录音机
提供2台录音机(pyaudio&;
arecord
)。我们可以使用环境变量RECORDER
来指定记录器。例如,runRECORDER=pyaudio alexa-tap
将使用pyaudio作为记录器。默认情况下,arecord
用作记录器。关键字检测器(可选)
使用口袋狮身人面像或雪童。要使用pocketspinx,请安装respeaker python library和pocketspinx。 要使用Snowboy,请转到Snowboy's Github安装它。
If you use raspberry pi and gstreamer, it is likely that gstreamer's default audio sink is GstOMXHdmiAudioSink. It ignores ALSA configurations and outputs audio to HDMI. If you don't want to use HDMI audio output, you should run
sudo apt remove gstreamer1.0-omx gstreamer1.0-omx-rpi
要求
对于呼吸核心(MT7688)
默认情况下,gstreamer1.0、pyaudio和pocketshinx以及respeaker python库已经安装,只需运行
pip install avs
对于debian/ubuntu/raspbian
sudo apt-get install mpg123 mpv sudo apt-get install gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \ gir1.2-gstreamer-1.0 python-gi python-gst-1.0 sudo apt-get install python-pyaudio
开始
运行
alexa-audio-check
检查录制和播放是否正常。如果rms不为零,则录制正常;如果听到警报,则播放正常$alexa-audio-check RMS: 41 RMS: 43
运行
alexa-auth
登录amazon,它会将授权信息保存到~/.avs.json
运行
alexa-tap
,然后按enter与alexa交谈
If you want to use a specified player, use the environment variable
PLAYER
to specify it, such asPLAYER=mpv alexa-tap
orPLAYER=mpg123 alexa
orPLAYER=gstreamer alexa
免提Alexa
使用Pocketshinx进行关键字定位
安装respeaker和pocketspinx python包
sudo pip install respeaker pocketsphinx # pocketsphinx requires gcc toolchain and libpulse-dev
运行
alexa
,然后使用“alexa”与alexa开始对话,例如,“alexa,几点了”
使用Snowboy进行关键字定位
安装Snowboy
git clone --depth 1 https://github.com/Kitt-AI/snowboy.git snowboy_github cd snowboy_github sudo apt install libatlas-base-dev swig python setup.py build sudo pip install .
安装语音引擎Python库
sudo pip install voice-engine
运行下面的python脚本并使用关键字
alexa
开始与alexa的对话importtimeimportsignalfromvoice_engine.sourceimportSourcefromvoice_engine.kwsimportKWSfromavs.alexaimportAlexaimportlogginglogging.basicConfig(level=logging.DEBUG)src=Source(rate=16000)kws=KWS(model='snowboy')alexa=Alexa()src.pipeline(kws,alexa)defon_detected(keyword):print('detected {}'.format(keyword))alexa.listen()kws.set_callback(on_detected)is_quit=[]defsignal_handler(signal,frame):print('Quit')is_quit.append(True)signal.signal(signal.SIGINT,signal_handler)src.pipeline_start()whilenotis_quit:time.sleep(1)src.pipeline_stop()
待办事项
- 扬声器接口
- 通知界面
更改Alexa语音服务客户端ID和产品ID
如果要使用自己的客户ID和产品ID,请尝试:
创建一个名为config.json的文件,其中包含您的产品ID、客户ID和客户机密
{ "product_id": "x", "client_id": "y", "client_secret": "z" }
运行
alexa-auth -c config.json
运行
alexa-tap
或alexa
许可证
GNU通用公共许可v3
学分
这个项目基于nicholas-gh/python-alexa-client
这个包是用cookiecutter和audreyr/cookiecutter-pypackage项目模板创建的。