Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto install script #57

Open
wants to merge 12 commits into
base: 2.0
Choose a base branch
from
Binary file removed .DS_Store
Binary file not shown.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,40 @@ Noise Delay | This increase the delay after the wake-up word has been activated
Sensitivity | This setting changes the sensitivity of the wake-up word detection. This setting is found on the front page for each command. The lower the number the less sensitive. | `20`


### Automatic Install (tested on 2020-02-13-raspbian-buster-lite)
If you wish to install it on your SO, you can use our automatic install script

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)


3. Edit the **wpa_supplicant.conf** in a text editor to match your wifi settings. Insert the card to the raspberry pi


4. In terminal ssh into the pi: ```sudo ssh [email protected]```<br>*Default password is 'raspberry'. To change password use the 'passwd' command*

5. Clone project_alias repo and execute install script:
```
sudo apt update -y && sudo apt upgrade -y && sudo apt install git -y
cd $HOME && git clone https://github.com/bjoernkarmann/project_alias.git
cd $HOME/project_alias/setup/ && ./install_script.sh
```

### Manual Install

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


3. Edit the **wpa_supplicant.conf** in a text editor to match your wifi settings. Insert the card to the raspberry pi


4. In terminal ssh into the pi: ```sudo ssh [email protected]```<br>*Default password is 'raspberry'. To change password use the 'passwd' command*

#### RaspberryPi Setup
How to prepare and setup a Raspberry Pi for this project:
Expand Down
3 changes: 2 additions & 1 deletion alias.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Requires=network.target

[Service]
Type=idle
Environment="DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus" "XDG_SESSION_TYPE=tty" "XDG_SESSION_CLASS=user" "XDG_SESSION_ID=c1" "XDG_RUNTIME_DIR=/run/user/1000"
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
WorkingDirectory=/home/pi/project_alias
StandardOutput=inherit
StandardError=inherit
Restart=always
Expand Down
13 changes: 12 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,16 @@ def run(self):
globals.GLOW = True
noise.stop()
print('say:', data['whisper'])
sound.speak(data['whisper'])
if data['whisper'].lower() == "ok google":
okgoogle.play()
time.sleep(0.6)
okgoogle.stop()
elif data['whisper'].lower() == "alexa":
alexa.play()
time.sleep(0.5)
alexa.stop()
else:
sound.speak(data['whisper'])
time.sleep(int(globals.SETTING['setting']['delay']))
noise.play()

Expand Down Expand Up @@ -214,6 +223,8 @@ def main():
#Initialize the sound objects
globals.initialize()
noise = sound.audioPlayer(globals.NOISE_PATH)
okgoogle = sound.audioPlayer(globals.OKGOOGLE_PATH)
alexa = sound.audioPlayer(globals.ALEXA_PATH)

thread_socket = Thread(target=socket_thread)
thread_socket.daemon = True
Expand Down
Binary file added data/alexa.wav
Binary file not shown.
Binary file added data/ok_google.wav
Binary file not shown.
Binary file removed imgs/.DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion modules/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def initialize():



global ROOT_PATH, KEYWORD_PATH, NOISE_PATH, SETTINGS_PATH
global ROOT_PATH, KEYWORD_PATH, NOISE_PATH, OKGOOGLE_PATH, ALEXA_PATH, SETTINGS_PATH

# absolute file paths
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
KEYWORD_PATH = os.path.join(ROOT_PATH, '../data/keyphrase.list')
NOISE_PATH = os.path.join(ROOT_PATH, '../data/noise.wav')
OKGOOGLE_PATH = os.path.join(ROOT_PATH, '../data/ok_google.wav')
ALEXA_PATH = os.path.join(ROOT_PATH, '../data/alexa.wav')
SETTINGS_PATH = os.path.join(ROOT_PATH, '../data/settings.txt')
Binary file removed setup/.DS_Store
Binary file not shown.
95 changes: 95 additions & 0 deletions setup/install_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash


# Check if cloned repository is in correct PATH
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`
if [[ "$SCRIPTPATH" != "$HOME/project_alias/setup" ]]; then
GIT_PATH=$(echo $SCRIPTPATH | sed "s/\/setup//g")
echo ""
echo "########################"
echo "Incorrect Git clone PATH"
echo "Actual: $GIT_PATH"
echo "Should be: $HOME/project_alias"
echo "########################"
echo ""
exit 1
fi


echo ""
echo "# Upgrade before start"
echo ""
sudo apt update -y -q
sudo apt upgrade -y -q

echo ""
echo "# Enable SPI module"
echo ""
sudo sed -i "s/#dtparam=spi/dtparam=spi/g" /boot/config.txt

echo ""
echo "# Enable pi user console autologin (needed to communicate to dbus)"
echo ""
sudo systemctl set-default multi-user.target
sudo ln -fs /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
sudo bash -c 'cat > /etc/systemd/system/[email protected]/autologin.conf << EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin pi --noclear %I \$TERM
EOF'

echo ""
echo "# Install python basic tools"
echo ""
sudo apt install -q -y python3-dev python3-pip git libatlas-base-dev

echo ""
echo "# Install ReSpeaker driver"
echo ""
cd $HOME
git clone https://github.com/respeaker/seeed-voicecard.git
cd seeed-voicecard
sudo ./install.sh

echo ""
echo "# Disable default soundcard"
echo ""
echo "blacklist snd_bcm2835" | sudo tee -a /etc/modprobe.d/alsa-blacklist.conf

echo ""
echo "# Installing python dependencies"
echo ""
sudo pip3 install spidev
sudo apt install -y -q python python-dev python-pip build-essential swig git libpulse-dev libasound2-dev pulseaudio pulseaudio-utils libpulse-dev libpulse-java libpulse0
sudo pip3 install --upgrade pocketsphinx

echo ""
echo "# Install espeak"
echo ""
sudo apt -y -q install espeak

echo ""
echo "# Install flask"
echo ""
sudo pip3 install flask flask_socketio

echo ""
echo "# Install pygame"
echo ""
sudo apt install -y -q python3-pygame

echo ""
echo "# Change alias service and install on systemd"
echo ""
cd $HOME/project_alias
sudo cp alias.service /lib/systemd/system/
sudo systemctl enable alias.service
echo ""
echo "####################"
echo "# Executing REBOOT #"
echo "####################"
echo ""
sudo reboot