hugvey/README.md

283 lines
8.7 KiB
Markdown
Raw Permalink Normal View History

2019-01-23 15:26:44 +01:00
# Hugvey / Pillow Talk
2019-03-07 20:19:43 +01:00
- Panpoticon
+ Fancy nickname for the web interface that allows altering the story and running the individual Hugveys
- Voice
+ Lyrebird voice syntehsis API wrapper. Set the oAuth token using a token generated [here](http://hugvey.rubenvandeven.com/oauth.php)
- Client
+ Individual Hugveys that stream their mic output and play audiofiles trough the Panopticon. Communication with the server is done through zmq
+ Connect with them trough hugvey1.local etc (1-25).
- Central Command/server
+ One server to rule them all. Start individual threads/subprocesses for the individual Hugveys. The Panopticon is started when starting the server.
2019-01-23 15:26:44 +01:00
## Server
Run the server: `python hugvey_server.py --config server_config.yml`
2019-11-14 16:20:48 +01:00
To make sure: don't run the server in a screen subterminal, as the amount of output can clog the server
### Screen commands:
Set scrollbuffer in `~/.screenrc`: as described [here](https://stackoverflow.com/a/8760452)
`ctrl+a d`: detach, `ctrl+a esc`: scroll the buffer, `ctrl+a i`: current buffer settings
2019-01-23 15:26:44 +01:00
### Panopticon
The server also integrates the _panopticon_, the monitoring & administration interface to Hugvey.
## Client
To run it: `python hugvey_client.py -c client_config.yml`
## Development
The Panopticon uses gulp to compile SASS into CSS, and to set up browser-sync for css & js. For now, no js user facing dependencies are managed trough node/npm.
2019-03-07 20:19:43 +01:00
After starting the server:
```bash
cd www
gulp
```
2019-03-07 21:10:49 +01:00
To run a command on all hugveys:
```
fab -H rubenvandeven.com,saclab@projects.rubenvandeven.com -- uname
```
2019-03-07 20:19:43 +01:00
## Installation
create and load Python virtualenv
```bash
virtualenv -p python3 --system-site-packages venv
source venv/bin/activate
```
Install requirements
```bash
apt install libasound-dev python3-pyaudio git-lfs
pip install -r requirements.server.txt
pip install -r requirements.txt
```
Install soft requirements (These are hard requirements for the clients!)
```
apt install sox rsync
```
Don't forget to init git submodules
```
git submodule init
git sumodule update
```
2019-03-28 16:26:17 +01:00
2019-03-29 16:20:23 +01:00
2019-04-11 12:42:22 +02:00
copy autossh-hugvey.service to `/etc/systemd/system/`:
```bash
cp autossh-hugvey.service /etc/systemd/system/autossh-hugvey.service
2019-04-27 16:39:20 +02:00
sudo systemctl enable autossh-hugvey.service
2019-04-11 12:42:22 +02:00
```
2019-03-29 16:20:23 +01:00
### clients
```
apt install supervisor
```
Add the following to the first section of `/etc/supervisor/supervisord.conf`
```
chown=pi:pi
```
2019-03-28 16:26:17 +01:00
## Deploy / usefull commands
2019-05-12 14:42:50 +02:00
rsync them all
2019-03-28 16:26:17 +01:00
```bash
2019-07-10 10:59:07 +02:00
for i in {1..26}; do echo $i; rsync -av ~/hugvey/ pi@hugvey$i.local:/home/pi/hugvey/ --exclude=www --exclude=venv --exclude=local --exclude=*.pyc --exclude=.git --exclude=recordings --exclude=/voice* --exclude=/pd --exclude=Lanbox; done
2019-03-28 16:26:17 +01:00
```
2019-03-29 16:20:23 +01:00
2019-05-12 14:42:50 +02:00
shut all of them down
2019-03-29 16:20:23 +01:00
```bash
2019-05-12 14:42:50 +02:00
for i in {1..26}; do ssh pi@hugvey$i.local "sudo shutdown -h now"; done
2019-03-29 16:20:23 +01:00
```
2019-05-12 14:42:50 +02:00
restart supervisor on all of them
```bash
2019-05-12 14:42:50 +02:00
for i in {1..26}; do ssh pi@hugvey$i.local "supervisorctl restart hugvey_client"; done
```
2019-05-12 14:42:50 +02:00
install bash on all of them
```bash
for i in {1..26}; do echo $i;ssh pi@hugvey$i.local "cd hugvey && sudo bash install_server.sh"; done
```
2019-08-28 10:59:58 +02:00
make them say their number
```bash
for i in {1..26}; do echo $i;ssh pi@hugvey$i.local "espeak -f /etc/hostname"; done
```
2019-05-12 14:42:50 +02:00
2019-11-14 17:40:27 +01:00
Select wifi network:
```bash
for i in {1,2,3,6,7,8,12,13,17,18,20,22}; do echo $i;ssh pi@hugvey$i.local "/sbin/wpa_cli -i wlan0 select_network 0"; done
```
### Monitoring the server processes
To make sure it will not die with 'Too many files open'
2019-03-29 16:20:23 +01:00
examine open file limit with `ulimit -a` and set it with `ulimit -n NUMBER`
```bash
lsof -p $(ps aux|grep "[h]ugvey_server.py" |awk '{print $2}')| awk '{print $9}'|sort -rn|uniq -c|sort -rn|head -20
```
or
```bash
lsof | grep $(ps aux|grep "[h]ugvey_server.py" |awk '{print $2}')| awk '{print $11}'|sort -rn|uniq -c|sort -rn|head -20
```
## Branches
multichannel
: Experiment with using alsa+sox to stream multiple channels to google.
# Create Story
## Messages
Things that can/will be said by Hugvey
Text
: The text that will be said. Or just a description if custom audio is uploaded. Variables can be entered by predending them with a $dollar_sign.
Start
: Mark message as being the start of a strand/tree of messages. Used for eg. diversions and formatting of the editor
Beginning
: There can only be one beginning. This is the message that the Hugvey will start with when starting the story.
Chapter Start
: A chapter can be marked. This is used by the timeout diversions, as it only returns to the next chapter marker after diversion. Furthermore, it is used by diversions to prevent them from triggering if specific sections (chapter markers) have been played.
Audio
: Upload a custom audio file to override the auto generated file
Afterrun time
: _deprecated_ Was the time the microphone kept listening after triggering this message. It was used to have the Hugvey reconsider its direction. Not used anymore
Volume factor
: Parameter send to the `play` command to increase/decrease the playback volume
Tempo factor
: Parameter send to the `play` command to increase/decrease the playback speed
Pitch factor
: Parameter send to the `play` command to increase/decrease the playback pitch (minus values for lower pitch)
Color
: Color the message aids in finding it in the editor window. Also is used by _replycontains_ diversions to prevent from running in specific moments
## Directions
Directions connect messages from one to the other. Can be created in the editor by selecting a message, and shift+click on its follow-up message. Another way is to select a message and press 'create message' from the right bar. This new message will automatically be connected and inherit the same color.
## Condition
Messages only head to a specific following message when one of the direction's conditions is matched (OR-condition). First come, first served.
The Conditions Description field allows for giving some info on the condition's reasons.
Types of conditions:
- timeout: timing finishing the playback of the message's audio
+ seconds: the duration
+ Only if no reply: timeout will be disabled after the person has spoken anything
+ Reply needed: If checked, the timeout is counted when it is met. This counter is used by the consecutive-timeouts diversions.
- replyContains: Match the contents of the speech using a regex. Or just any speech. Used to capture variables.
+ regex: The regex to match on. Variables can be matched using the python syntax to give the variable a name (?P<variable_name>\w+)
+ three consecutive timings can be given:
+ delay reply duration: the duration of the reply since hugvey stopped speaking. If it is more than this value (but less than the larger) it will use the given timing
+ delay wait time: The time to wait after a person speaks. It doesn't wait for Google's `is_finished` parameter, but rather checks from Google's last response. This way, also short utterances sutch as 'hey' or 'ok' are also properly timed, as these often don't get an is_finished by Google.
+ instant match: don't use any timings. the moment the regex matches on the speech in progress, the condition is met.
- variable: returns True if variable is set
+ TODO
- diversion: returns True if diversion has ben taken.
+ TODO
## Diversions
- ReplyContains: Match the contents of speech using regex.
+ works only if the current message has one, and only one, direction.
2019-05-01 13:09:13 +02:00
2019-05-06 08:13:13 +02:00
times occured/only on n-th instance: determines the order of diversions of the same type (for Timeout and no_response). Starting at 1, as a diversion with value of 0 can occur always
# Network
## 4G Modem
Visit 192.168.5.1
2019-05-11 15:23:55 +02:00
The password is at the bottom of the device.
2019-05-12 14:42:50 +02:00
# Restoring a hugvey
- Write image `/mnt/stash/hugvey.img` to the microSD card.
+ You can use `gnome-disks` 'restore image' for that
- Open partition called rootfs, and `sudo nano etc/hostname`
+ Change hugvey20 into hugveyX (the number you need)
- Start it, rsync, install_server.sh as mentioned above.
2019-11-14 17:40:27 +01:00
# Pure Data patch
The pure data patch controls the loop for both the python script and the max patch.
If there's a click in the audio (which randomly occurs), change audio settings. For some reason PD cannot remember/store these.
So after each start of PD set Audio Settings:
Sample rate
: 44100
Block size
: 1024
Delay, msec
: 50
## Static file server
To prevent the hugveys from waiting for a suboptimal tornado server, static files can be fetched from a serparate lighttpd server.
Installed with `apt install lighttpd`.
In `/etc/lighttpd/lighttpd.conf` set port to `8889` and add an alias for the local dir:
```
alias.url = ("/local/" => "/home/hugvey/hugvey/local/")
```
2020-02-18 14:29:30 +01:00
## When Telegram is blocked
In Russia, Telegram is blocked, to circumvent this, we set it to run over a SOCKS proxy:
`autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -N -D 9090 rubenvandeven.com`