Skip to main content

Voice Assistant

PyPI - Downloads

Open-source customizable voice assistant

Features

  1. Trigger word can be said anywhere in a sentence, for example, "play music, Jarvis". Few last seconds of audio input are recoded into memory, so when trigger word is said, pre-recorded audio data is also processed
  2. Speech is processed continuously while user is speaking which, for certain requests, results in a very fast action/response
  3. Integration with Home Assistant REST API allows to define custom skills and link HASS entities via a simle config
  4. Text-to-Speech relies on Amazon Polly and allows to pick a custom voice from available Polly voices
  5. Voice Assistant REST API enables remote control. For example, it can be used to make Voice Assistant say something when Home Assistant automation is triggered

Running in virtual environment (Python 3.6+)

  1. Install dependencies:
    sudo apt-get update
    sudo apt-get install -y libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0\
    python3-pyaudio python3-venv mpg123
    
  2. Create virtual environment and install with pip:
    python3 -m venv vass-venv
    source vass-venv/bin/activate
    pip install voiceassistant
    
  3. Start with command: vass

Running on Docker

Docker Installation guide. Raspbian only supports installation with convenience script.

  1. Download and build Voice Assistant on Docker

    git clone https://github.com/vadimtitov/voice-assistant
    cd voice-assistant
    docker build -t voice-assistant .
    
  2. Create a folder to store configuration files e.g.

    mkdir -p ~/.config/voice-assistant
    
  3. Run with Docker Compose:

  • Create docker-compose.yaml:
    version: '1'
    services:
     voice-assistant:
       container_name: voice-assistant
       image: voice-assistant
       volumes:
         # volume to share config and credentials from host to container
         - <YOUR/CONFIGURATION/FOLDER>:/usr/src/config
       devices:
         # sounds devices need to be exposed to container
         - /dev/snd:/dev/snd
       restart: unless-stopped
       network_mode: host
    
  • Start with: docker-compose up

First-time configuration

On the first start configuration.yaml and google_credentials.json files will be auto-generated inside voice assistant configuration folder. If running on Docker configuration folder path is chosen manually as per instructions above. If running in virtual environment, folder path is automatically chosen as /home/<username>/.config/voiceassistant/

As Voice Assistant relies on external engines for Speech-To-Text and Text-to-Speech the following needs to be set up:

  1. Google Cloud Speech-To-Text
  1. AWS for Text-to-Speech
  • Create AWS account and take a note of Access Key ID and Secret Access Key
  • Insert the above into configuration.yaml:
    tts:
     aws:
       access_key_id: "YOUR_ACCES_KEY_ID"
       secret_access_key: "YOUR_SECRET_ACCESS_KEY"
       ...
    

Customization

Currently the following customization options (YAML-paths) are available to specify in configuration.yaml:

  • triggerword.picovoice.word - trigger word to use, the following words are available in Picovoice porcupine: alexa, americano, blueberry, bumblebee, computer, grapefruit, grasshopper, hey google, hey siri, jarvis, ok google, pico clock, picovoice, porcupine, smart mirror, snowboy, terminator, view glass
  • triggerword.picovoice.sensitivity - trigger word sensitivity, a number within [0, 1]
  • stt.google_cloud.language_code - one of language codes for STT
  • tts.aws.region_name - one of AWS region names, set closest to your location
  • tts.aws.voice_id - one of Polly Voice Samples

Integrating with Home Assistant

If haven't already, enable Home Assistant API and generate access token: in HASS Web UI click on your profile, scroll down to "Long-Lived Access Tokens" and click "create token".

Add record to configuration.yaml:

hass:
  url: http://<your.hass.address>:8123
  token: <your_access_token>

There are 2 types of integration with HASS:

  1. Exposing HASS entities, for example:

      hass:
        ...
        entities:
          - ids:
            - switch.bedroom_light_1
            - switch.bedroom_light_2
            names:
            - lights
          - ids:
            - cover.curtain_bedroom
            names:
            - curtain
            - blinds
    

    The above sample configuration will allow user to control lights and blinds with the following phrases:

    • turn on lights, lights on, enable lights, start lights, lights off, disable lights, etc
    • open blinds, blinds up, open curtains, close curtains, etc

    Note that this only supports "binary" types of entities e.g. the ones that have turn_on-turn_off or open_cover-close_cover services.

  1. Creating custom skills

    Custom skills can be defined by providing 3 things:

    1. Arbitrary skill name
    2. List of speech expressions that trigger the skill (can be regex)
    3. List of actions to execute when skill is triggered

    Currently available actions:

    Action Arguments
    say_from_template template
    call_service service, entity_id, any additional data
    fire_event event_type, event_data
    set_state entity_id, state
    run_script script_id

    Consider an example:

      hass:
        ...
        skills:
          - name: good_morning
            expressions:
              - good morning
              - (wake&&time)
            actions:
            - action: run_script
              script_id: good_morning
            - action: say_from_template
              template: Good Morning. The temperature outside is {{ state_attr('weather.my_home','temperature') }} degrees.
    

    When user says "good morning" or "time to wake up" Voice Assistant will execute two actions:

    • run_script - execute HASS script with id good_morning
    • say_from_template - say a phrase rendered by HASS Jinja2 template

Metadata

Release files for voiceassistant 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for voiceassistant 0.3.0
File Size Uploaded
voiceassistant-0.3.0.tar.gz 234.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for voiceassistant 0.3.0
File Interpreter ABI Platform
voiceassistant-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 472.5 kB

Release files / voiceassistant-0.3.0.tar.gz

Download URL voiceassistant-0.3.0.tar.gz
Size 234.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3980fd91a545a2807cffc037caa592a54731d9f8edaa9356af1d6952cfae44dc
BLAKE2b-256 checksum
How to use checksums
735da5e8b5a5529be99ea8d5fff3509ea211a5a9c570d8e2a20a00edc04561bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

Release files / voiceassistant-0.3.0-py3-none-any.whl

Download URL voiceassistant-0.3.0-py3-none-any.whl
Size 238.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1af7e45593aa43f3c30012dd2d12fc23fa54c46d40e9f5d6456506c6196eaaac
BLAKE2b-256 checksum
How to use checksums
4e51c46d07d903f274736c4cd740406eb64f9544a8ca092d297066b9845c3bd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

Release history Release notifications | RSS feed

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page