Package: avs
Python Alexa Voice Service AppFeaturesSupport Alexa Voice Service API v20160207Support multiple audio players: gstreamer 1.0, mpv and mpg123支持Baidu DuerOSOptionsPlayerWe have 3 players (mpv,mpg123and gstreamer) to use.SpeechSynthesizerandAlertsprefermpg123which is more responsive.AudioPlayerlikes gstreamer >mpv>mpg123. Gstreamer supports more audio format and works well on raspberry pi. We can also specify the player ofAudioPlayerusing the environment variablePLAYER.Recorder2 recorders (pyaudio &arecord) are available. We can use environment variableRECORDERto specify the recorder. For example, runRECORDER=pyaudio alexa-tapwill use pyaudio as the recorder. By default,arecordis used as the recorder.Keyword detector (optional)Use PocketSphinx or Snowboy. To use pocketsphinx, install respeaker python library and pocketsphinx.
To use Snowboy, go toSnowboy's Githubto 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 runsudo apt remove gstreamer1.0-omx gstreamer1.0-omx-rpiRequirementsFor ReSpeaker Core (MT7688)gstreamer1.0, pyaudio and pocketsphinx and respeaker python library are already installed by default, just runpip install avsFor Debian/Ubuntu/Raspbiansudo 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-pyaudioGet startedrunalexa-audio-checkto 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: 43runalexa-authto login Amazon, it will save authorization information to~/.avs.jsonrunalexa-tap, then press Enter to talk with alexaIf you want to use a specified player, use the environment variablePLAYERto specify it, such asPLAYER=mpv alexa-taporPLAYER=mpg123 alexaorPLAYER=gstreamer alexaHands-free AlexaUsing PocketSphinx for Keyword Spottinginstall respeaker and pocketsphinx python packagessudo pip install respeaker pocketsphinx  # pocketsphinx requires gcc toolchain and libpulse-devrunalexa, then use "alexa" to start a conversation with alexa, for example, "alexa, what time is it"Using Snowboy for Keyword SpottingInstallSnowboygit 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 librarysudo pip install voice-enginerun the following python script and use the keywordalexato start a conversation with alexaimporttimeimportsignalfromvoice_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()To doSpeaker interfaceNotifications interfaceChange Alexa Voice Service client id and product idIf you want to use your own  client id and product id, try:register for an Amazon Developer Accountcreate a file named config.json with your product_id, client_id and client_secret{
     "product_id": "x",
     "client_id": "y",
     "client_secret": "z"
 }runalexa-auth -c config.jsonrunalexa-taporalexaLicenseGNU General Public License v3CreditsThis project is based onnicholas-gh/python-alexa-clientThis package was created with Cookiecutter_ and theaudreyr/cookiecutter-pypackageproject template.