Skip to main content

Python implementation of Alexa Voice Service App

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

Requirements

Choose a player from mpv, mpg123 and gstreamer. SpeechSynthesizer and Alerts prefer mpg123 as it 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 of AudioPlayer using the environment variable PLAYER.

  • one of mpg123, mpv and gstreamer 1.0
  • python-pyaudio
  • respeaker python library, pocketsphinx and snowboy (optional, for hands-free keyword spotting)

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

Installation

  • 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-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

  1. 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

  2. run alexa-auth to login Amazon, it will save authorization information to ~/.avs.json

  3. 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 as PLAYER=mpv alexa-tap or PLAYER=mpg123 alexa or PLAYER=gstreamer alexa

Hands-free Alexa

Using PocketSphinx for Keyword Spotting

  1. install respeaker and pocketsphinx python packages

    sudo pip install respeaker pocketsphinx # pocketsphinx requires gcc toolchain and libpulse-dev

  2. run alexa, then use "alexa" to start a conversation with alexa, for example, "alexa, what time is it"

Using Snowboy for Keyword Spotting

  1. Install Snowboy python library

  2. Install voice-engine python library

    sudo pip install voice-engine

  3. run the following python script and use the keyword alexa to start a conversation with alexa

     import signal
     from voice_engine.source import Source
     from voice_engine.kws import KWS
     from avs.alexa import Alexa
    
    
     src = Source(rate=16000)
     kws = KWS(model='alexa')
     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:

  1. register for an Amazon Developer Account

  2. create a file named config.json with your product_id, client_id and client_secret

    { "product_id": "x", "client_id": "y", "client_secret": "z" }

  3. run alexa-auth -c config.json

  4. run alexa-tap or alexa

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

avs-0.3.0.tar.gz (214.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

avs-0.3.0-py2.py3-none-any.whl (217.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file avs-0.3.0.tar.gz.

File metadata

  • Download URL: avs-0.3.0.tar.gz
  • Upload date:
  • Size: 214.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for avs-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d5471f2184c67dbcff4a175d50a966c45cd758d15d62664ad890c5e1d3f950b8
MD5 660cab58c7600bae10239e10f3b5ada6
BLAKE2b-256 f90d4a302888818596437ef3682fa5b584e210264d703b20533e14a0ec4a793f

See more details on using hashes here.

File details

Details for the file avs-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: avs-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 217.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for avs-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2da43515590de0bd456456329d52ece733faed1ab1adec2b4c72cef510a9e80c
MD5 c8464aa91595f9a5eb37f708c1b2951e
BLAKE2b-256 aee8d01052d543999e08cc88e9ceee31af415da499fbc3e3819a33c9f50aadf2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page