Alexa Voice Service Python SDK
Project description
Python Alexa Voice Service App
Features
- Support Alexa Voice Service API v20160207
- Support multiple audio players: gstreamer 1.0, mpv and mpg123
- 支持Baidu DuerOS
Options
-
Player
We have 3 players (
mpv
,mpg123
and gstreamer) to use.SpeechSynthesizer
andAlerts
prefermpg123
which is more responsive.AudioPlayer
likes gstreamer >mpv
>mpg123
. Gstreamer supports more audio format and works well on raspberry pi. We can also specify the player ofAudioPlayer
using the environment variablePLAYER
. -
Recorder
2 recorders (pyaudio &
arecord
) are available. We can use environment variableRECORDER
to specify the recorder. For example, runRECORDER=pyaudio alexa-tap
will use pyaudio as the recorder. By default,arecord
is used as the recorder. -
Keyword detector (optional)
Use PocketSphinx or Snowboy. To use pocketsphinx, install respeaker python library and pocketsphinx. To use Snowboy, go to Snowboy's Github to install it.
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
Requirements
-
For ReSpeaker Core (MT7688)
gstreamer1.0, pyaudio and pocketsphinx and respeaker python library are already installed by default, just run
pip install avs
-
For 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
Get started
-
run
alexa-audio-check
to check if recording & playing is OK. If RMS is not zero, recording is OK, if you can hear alarm, playing is OK$alexa-audio-check RMS: 41 RMS: 43
-
run
alexa-auth
to login Amazon, it will save authorization information to~/.avs.json
-
run
alexa-tap
, then press Enter to talk with 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
Hands-free Alexa
Using PocketSphinx for Keyword Spotting
-
install respeaker and pocketsphinx python packages
sudo pip install respeaker pocketsphinx # pocketsphinx requires gcc toolchain and libpulse-dev
-
run
alexa
, then use "alexa" to start a conversation with alexa, for example, "alexa, what time is it"
Using Snowboy for Keyword Spotting
-
Install 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 .
-
Install voice-engine python library
sudo pip install voice-engine
-
run the following python script and use the keyword
alexa
to start a conversation with alexaimport time import signal from voice_engine.source import Source from voice_engine.kws import KWS from avs.alexa import Alexa import logging logging.basicConfig(level=logging.DEBUG) src = Source(rate=16000) kws = KWS(model='snowboy') alexa = Alexa() src.pipeline(kws, alexa) def on_detected(keyword): print('detected {}'.format(keyword)) alexa.listen() kws.set_callback(on_detected) is_quit = [] def signal_handler(signal, frame): print('Quit') is_quit.append(True) signal.signal(signal.SIGINT, signal_handler) src.pipeline_start() while not is_quit: time.sleep(1) src.pipeline_stop()
To do
- Speaker interface
- Notifications interface
Change Alexa Voice Service client id and product id
If you want to use your own client id and product id, try:
-
create a file named config.json with your product_id, client_id and client_secret
{ "product_id": "x", "client_id": "y", "client_secret": "z" }
-
run
alexa-auth -c config.json
-
run
alexa-tap
oralexa
License
GNU General Public License v3
Credits
This project is based on nicholas-gh/python-alexa-client
This package was created with Cookiecutter_ and the audreyr/cookiecutter-pypackage project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file avs-0.5.5.tar.gz
.
File metadata
- Download URL: avs-0.5.5.tar.gz
- Upload date:
- Size: 218.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3aabe1a45fe85d98b65b0981d6d109f11cf3c005ba44002e76c29dd2dca2c2cb |
|
MD5 | 56402214e7e5732d9da631180badcfd6 |
|
BLAKE2b-256 | 909ccb3de628e96b52ed3703caa3b50f23af7b764a80de3da615b439e50757fc |
File details
Details for the file avs-0.5.5-py2.py3-none-any.whl
.
File metadata
- Download URL: avs-0.5.5-py2.py3-none-any.whl
- Upload date:
- Size: 220.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adfd4b760a1bc6a58eabd0dbb02fc9db88d60c5c884dd03065815233a1e55337 |
|
MD5 | d2ece861dc7f59a4d77e4c0ce82a82ae |
|
BLAKE2b-256 | bd73e420be72c5723834ef0d5499a05a029c51caf84d521836724a6813a8f4c9 |