Skip to content

Commit

Permalink
Alias 2.0 finalizing
Browse files Browse the repository at this point in the history
- New sensitivity changer
- Final and tested dmg file
- Final readme
  • Loading branch information
Bjørn Karmann committed Dec 28, 2019
1 parent 1c0fab8 commit 0b9aec2
Show file tree
Hide file tree
Showing 52 changed files with 290 additions and 535 deletions.
Binary file modified .DS_Store
Binary file not shown.
150 changes: 84 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,81 @@
# Project Alias
# Project Alias 2.0

<p float="left">
<img src="imgs/alias.jpg" width="49%"> <img src="imgs/short_alias_explained.gif" width="49%">
</p>

[![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![License: GPL](https://img.shields.io/badge/license-GPL-blue)

Project Alias is an open-source parasite to hack smart home devices. Train custom wake-up names and commands for your devices while disturbing their built-in microphone with noise. Introduce false labelling to their algorithm by changing gender or nationality. Read more about the project **[here](http://bjoernkarmann.dk/project_alias)**.
Project Alias is an open-source parasite to hack smart home devices. Train custom wake-up names and commands for your devices while disturbing their built-in microphone with noise. Introduce false labelling to their algorithm by changing gender or nationality. Read more about the project **[here](http://bjoernkarmann.dk/project_alias)**


```diff
- WARNING:
- V2.0 is work in progress and will be updated soon!
```

This repository has been updated to 2.0. Find the old version **[here](http://bjoernkarmann.dk/project_alias)**.
This repository has been updated to 2.0 Find the old version **[here](http://bjoernkarmann.dk/project_alias)**

### 2.0 Features
- Multiple trigger words
- Custom whisper commands
- New and better word detection
- Change gender
- Change language
- Adjust trigger sensitivity and delay
- Multiple wake-up words
- Custom commands to be told to the assistant
- Change gender and language of Alias
- Adjust wake-up word sensitivity and delay
- New wake-up word detection powered by **[Pocketsphinx](https://cmusphinx.github.io/)**

### Build Guide
For the complete step-by-step guide and 3D files see our **[Instructables](https://www.instructables.com/id/Project-Alias)**.
For the complete step-by-step guide and 3D files see our **[Instructables](https://www.instructables.com/id/Project-Alias)**


### Easy Setup 🔧
We have made the setup even easier with a SD-card clone of our working Alias.
1. **[Download]()** the latest .img file
2. Use **[Etcher](https://etcher.io/)** to flash a micro SD card with the .img file.
3. Insert the micro SD card into the Raspberry Pi A+.
4. Log on to the wifi name **"Project Alias"** and open the browser.
The Alias software can be flashed onto a micro SD card, for a fast and easy setup. Make sure the respeaker hat is attached to the Raspberry Pi.
1. **[Download](https://www.dropbox.com/s/g6hh5e4ml65jcaf/alias2_0.dmg?dl=0)** the *alias2_0.dmg* file
2. Use **[Etcher](https://www.balena.io/etcher/)** to flash a micro SD card with the .dmg file
3. Insert the micro SD card into the Raspberry Pi 3A+
4. Power Alias up and wait for the yellow light to glow



*We recommend to use the Easy Setup but if you wish to install the project from scratch use the **Manual Install** instructions.*

### Start using Alias 🍄

1. Configure your Alias by connecting to its local wifi from your phone.
<br>ssid: **Project Alias** psw: **cordyceps**.

*We recommend to use the Easy Setup but if you wish to install the project from scratch use the [Raspberry Pi Setup]() instrucrtions.*
2. Open a browser and enter the url: **alias.local** to interface with Alias.

### Using Alias 🍄
1. To start using Alias, log on the wifi network called "Project Alias" with any device.
3. From the interface you can now add new wake-up word / commands or edit existing ones. Save any changes by clicking the **Update Alias** button. We recommend to experiment with different words and sensitivity levels to find what works best for you.

2. Rename
4. To configure the settings, click the icon in the upper right corner. Here you can adjust and customize the noise, language, gender, volume and delay.
*Tip: If you write the full command into alias you can create shortcuts and new functions. E.g. By calling 'Funky Time' you
could have Alias whisper 'Ok Google, play some funky music on Spotify'.*

3. Under the menu, click **Train Alias** and wait a few seconds for the model to learn the name. This name does not necessarily need to be a word but can be a sound and any language. So be creative! You can always reset your name on the menu. *Tip: it helps to record the name from different locations in your home.*

4. Try it out! Say the name and ask your question once you see a blue light on the device or on your phone.
Note: once trained there is no need to have the phone connected anymore.
![User interface](imgs/ui.jpg)


*If you find Alias is not responding correctly, try to train a few more examples. Or if you find Alias is triggering to often, you can go to the menu and turn background sound ON. This toggles the background mode and adds any new recordings to the background examples. Record and train just as before, but try to capture unique sounds in your environment or even words that sound similar to your chosen name.*

### Settings ⚙️

Setting | Description | Default
--- | --- | ---
Noise | This will turn on/off the looping noise| `ON`
Gender | -- | `Female`
Language | Change the language Alias uses to | `English`
Volume | Change the volume of the speakers. This needs to be heigh enough for the noise to block the assistant, but low enough not to be audible. | `10`
Sensitivity | This setting changes the sensitivity of the word detection. The lower the number the less sensitive. This setting can be helpful for short words. | `3`
Noise Delay | This increase the delay after from the trigger word to the restart of the noise. This is used as a noise free window, when asking the assistant a equation. | `10s`
Gender | Choose what gender the assistant should perceive when Alias whispers commands. By changing to the opposite gender you will able to introduce false labelling into the assistants algorithm. This confusion might lead to interesting interactions and answers. Note, this only changes the voice of Alias itself, and will therefore only have an effect with long commands. | `Male`
Language | Change the language Alias uses to speak to your assistant. This is to introduce another layer of noise that makes the system label you with a different nationality. To use this feature the command for the assistant has to be written in the same language. | `English`
Volume | Change the volume of the speakers. This needs to be loud enough for the noise to block the assistant, but low enough not to be audible. Settings can vary by acoustics and ambient inferences. | `39`
Sensitivity | This setting changes the sensitivity of the wake-up word detection. The lower the number the less sensitive. This setting can be helpful for short words. | `20`
Noise Delay | This increase the delay after the wake-up word has been activated to restart the noise again. This is used as a noise free window, when asking the assistant a question. It should be set to match the appropriate time interval needed for the maximum length of a conversation. | `10s`



### Manual Install

### Raspberry Pi Setup
If you wish to build this project manually, you can follow the guide below. We do recommend using the pre installed image linked in the Easy Setup.

How to prepare and setup a Raspberry Pi for this project:
#### RaspberryPi Setup
How to prepare and setup a Raspberry Pi for this project:

1. Download the latest version of [Raspbian](https://www.raspberrypi.org/downloads/raspbian/) and flash your micro SD card with [Etcher](https://etcher.io/)
1. Download the latest version of **[Raspbian Stretch](https://www.raspberrypi.org/downloads/raspbian/)** and flash your micro SD card with **[Etcher](https://etcher.io/)**

2. Copy the **ssh** and **wpa_supplicant.conf** files from the [setup folder](setup/) to the SD card (boot)

2. Copy the **ssh** and **wpa_supplicant.conf** files from the **[setup folder](setup/)** to the SD card (boot)


3. Edit the **wpa_supplicant.conf** in a text editor to match your wifi settings. Insert the card to the raspberry pi
Expand All @@ -80,64 +88,74 @@ How to prepare and setup a Raspberry Pi for this project:
7. Reboot ```sudo reboot```


#### Installing

#### Installing Dependencies

On the Rapsberry Pi: clone and install the sound driver for the [ReSpeaker](http://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT/) hat:<br>
*This is only required when using the ReSpeaker hat, this code will also work with other sound drivers.*
*Note: Some dependencies might very for differen versions. This guide has last been tested and validated on Raspbian Stretch version 9.*

On the Rapsberry Pi: Enable interface SPI in raspi-config
```
cd && git clone https://github.com/respeaker/seeed-voicecard.git
cd seeed-voicecard && sudo ./install.sh
raspi-config
```

Install **Tensorflow** and **Keras**:

Make sure you have python3 and git installed for the next steps:
```
sudo apt-get install python3-dev python3-pip git libatlas-base-dev
sudo pip3 install tensorflow keras
```

Install the required modules:
Clone and install the sound driver for the **[ReSpeaker](http://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT/)** hat:<br>
*– This is only required when using the ReSpeaker hat, this code will also work with other sound drivers.*

```
sudo apt-get install python3-numpy python3-spidev python-h5py
sudo apt-get install python3-pyaudio libsdl-ttf2.0-0 python3-pygame
sudo pip3 install flask flask_socketio python_speech_features
cd && git clone https://github.com/respeaker/seeed-voicecard.git
cd seeed-voicecard && sudo ./install.sh
```

Clone the **Alias** project:
Disable default sound card by following this **[guide](https://www.instructables.com/id/Disable-the-Built-in-Sound-Card-of-Raspberry-Pi/)**

Install **pocketsphinx** and dependencies
```
git clone https://github.com/bjoernkarmann/project_alias.git
sudo pip3 install spidev
sudo apt-get install -y python python-dev python-pip build-essential swig git libpulse-dev
sudo apt-get install libasound2-dev
sudo apt-get install pulseaudio pulseaudio-utils libpulse-dev libpulse-java libpulse0
sudo pip3 install --upgrade pocketsphinx
```

Setup a bootscript. Open this file:
Install **espeak**

```
sudo nano /etc/rc.local
sudo apt-get install espeak
```
and add at the end of the command just before **exit 0**, like:

Install **flask** server
```
cd project_alias && python3 app.py &
sudo pip3 install flask flask_socketio
```
Now reboot the Pi to test it:

Install **pygame**
```
sudo reboot
sudo apt-get install python3-pygame
```

## Calibration
To install a private network you can follow this **[guide](https://github.com/raspberrypi/documentation/pull/1097/files)**


Finally clone the **Alias** project:

```
git clone https://github.com/bjoernkarmann/project_alias.git
```


### Change assistant

- If you are using a **Amazon Alexa**, please change line 21 in **app.py** to: ```wakeup = sound.audioPlayer("data/alexa.wav",0,"wakeup", False)```
If you are using **Google Home** or an **Amazon Alexa** the way you change the wake up word is simply by writing it in the responds field in the Alias web-app

- To set the volume of the speaker you can change the line 32 in **modules/sound.py** ```os.system('sudo amixer -c 1 sset Speaker 83')```

## Contributors
Made by [Bjørn Karmann](http://bjoernkarmann.dk) and [Tore Knudsen](http://www.toreknudsen.dk/).
### Contributors
Made by **[Bjørn Karmann](http://bjoernkarmann.dk)** and **[Tore Knudsen](http://www.toreknudsen.dk/)**


## License
### License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
This project is licensed under the GPL License - see the [LICENSE.md](LICENSE.md) file for details
18 changes: 18 additions & 0 deletions alias.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Project Alias
After=network.target
Requires=network.target

[Service]
Type=idle
ExecStartPre=/usr/bin/python3 -u sleep.py
ExecStart=/usr/bin/python3 -u app.py > /home/pi/sample.log 2>&1
WorkingDirectory=/home/pi/project_alias-2.0
StandardOutput=inherit
StandardError=inherit
Restart=always
RestartSec=0
User=pi

[Install]
WantedBy=multi-user.target
Empty file modified app.py
100644 → 100755
Empty file.
Binary file removed data/background_sound_examples.npy
Binary file not shown.
Binary file removed data/background_sound_labels.npy
Binary file not shown.
5 changes: 1 addition & 4 deletions data/keyphrase.list
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
hey alias /1e-13/
funky time /1e-16/
marvin /1e-5/
weather man /1e-19/
hey alias /1e-20/
Empty file modified data/noise.wav
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion data/settings.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"setting": {"language": "English", "gender": "Female", "delay": "5", "volume": "51", "sensitivity": "0", "noise": true}, "keyphrase": [{"whisper": "Ok Google", "name": "Hey Alias"}, {"whisper": "Ok Google, play some funky music on spotify", "name": "Funky Time"}, {"whisper": "Ok Google", "name": "Marvin"}, {"whisper": "Ok Google, how is the weather today", "name": "Weather man"}]}
{"setting": {"noise": true, "language": "English", "volume": "39", "gender": "Male", "delay": "10"}, "keyphrase": [{"whisper": "Ok Google", "name": "Hey Alias", "sensitivity": "20"}]}
Binary file modified imgs/.DS_Store
Binary file not shown.
Binary file added imgs/ui.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed modules/.DS_Store
Binary file not shown.
Empty file modified modules/__pycache__/ai.cpython-35.pyc
100644 → 100755
Empty file.
Binary file modified modules/__pycache__/apa102.cpython-35.pyc
100644 → 100755
Binary file not shown.
Binary file modified modules/__pycache__/connect.cpython-35.pyc
100644 → 100755
Binary file not shown.
Empty file modified modules/__pycache__/connection.cpython-35.pyc
100644 → 100755
Empty file.
Binary file modified modules/__pycache__/globals.cpython-35.pyc
100644 → 100755
Binary file not shown.
Binary file modified modules/__pycache__/led.cpython-35.pyc
100644 → 100755
Binary file not shown.
Binary file modified modules/__pycache__/settings.cpython-35.pyc
100644 → 100755
Binary file not shown.
Binary file modified modules/__pycache__/sound.cpython-35.pyc
100644 → 100755
Binary file not shown.
Empty file modified modules/apa102.py
100644 → 100755
Empty file.
Empty file modified modules/connect.py
100644 → 100755
Empty file.
Empty file modified modules/globals.py
100644 → 100755
Empty file.
Empty file modified modules/led.py
100644 → 100755
Empty file.
12 changes: 5 additions & 7 deletions modules/settings.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ def read():
# get setting and write names into keyphrase.list file
def updateServer(data):
print(data)
sensitivity = data['setting']['sensitivity'] # 0 - 10
#sensitivity = data['setting']['sensitivity'] # 0 - 10

with open(globals.KEYWORD_PATH, 'w') as f:
for item in data['keyphrase']:
threshold = int(mapF(len(item['name']),4, 15, 0 , 30)) + int(sensitivity)
print(threshold)
keyphrase = item['name'] + " /1e-" + str(threshold) + "/"
#threshold = int(mapF(len(item['name']),4, 15, 0 , 30)) + int(sensitivity)
keyphrase = item['name'] + " /1e-" + str(item['sensitivity']) + "/"
keyphrase = keyphrase.lower()
f.write("%s\n" % keyphrase)


def mapF(x,in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
def mapF(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max-in_min) + out_min;
Empty file modified modules/sound.py
100644 → 100755
Empty file.
Binary file removed modules/static/.DS_Store
Binary file not shown.
Binary file removed modules/static/assets/.DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions modules/static/assets/downarrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified modules/static/assets/fonts/WorkSans-Black.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/WorkSans-Bold.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/WorkSans-ExtraBold.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/WorkSans-ExtraLight.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/WorkSans-Light.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/WorkSans-Medium.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/WorkSans-Regular.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/WorkSans-SemiBold.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/WorkSans-Thin.ttf
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/worksans-semibold-webfont.woff
100644 → 100755
Empty file.
Empty file modified modules/static/assets/fonts/worksans-semibold-webfont.woff2
100644 → 100755
Empty file.
Empty file modified modules/static/assets/plus.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified modules/static/assets/settings.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions modules/static/assets/uparrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0b9aec2

Please sign in to comment.