Skip to content

Commit

Permalink
multiple optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
hbarnard committed Dec 12, 2022
1 parent d2e1d08 commit eee0391
Show file tree
Hide file tree
Showing 22 changed files with 1,180 additions and 933 deletions.
Binary file modified __pycache__/intent_server.cpython-39.pyc
Binary file not shown.
113 changes: 113 additions & 0 deletions bits-and-pieces/RETROPIE ON OFF V1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@


VERSION 1.1
apt-get with the following command :


1. sudo apt-get install update

2. sudo apt-get install python-dev

3. sudo apt-get install python3-dev

4. sudo apt-get install gcc

5. sudo apt-get install python-pip




Next you need to get RPi.GPIO:

6. wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.11.tar.gz


Uncompress the packages:

7. sudo tar -zxvf RPi.GPIO-0.5.11.tar.gz



move into the newly created directory:

8. cd RPi.GPIO-0.5.11


install the module by doing:

9. sudo python setup.py install

10. sudo python3 setup.py install


creating a directory to hold your scripts:

11. mkdir /home/pi/scripts

call our script shutdown.py (it is written in python). Create and edit the script by doing:


12. sudo nano /home/pi/scripts/shutdown.py


The content of the script: Paste it in the blank area

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocess

# we will use the pin numbering to match the pins on the Pi, instead of the
# GPIO pin outs (makes it easier to keep track of things)

GPIO.setmode(GPIO.BOARD)

# use the same pin that is used for the reset button (one button to rule them all!)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)

oldButtonState1 = True

while True:
#grab the current button state
buttonState1 = GPIO.input(5)

# check to see if button has been pushed
if buttonState1 != oldButtonState1 and buttonState1 == False:
subprocess.call("shutdown -h now", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
oldButtonState1 = buttonState1

time.sleep(.1)


Press CRTL X Then Y



Restart the pi

13. sudo reboot



configure our script to run at startup,

14. sudo nano /etc/rc.local


Add the following to the file

sudo python /home/pi/scripts/shutdown.py &

Press CRTL X Then Y











80 changes: 43 additions & 37 deletions etc/mema.ini
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
[main]
pi = True
db = /home/pi/mema/db/memories.db
media_directory = /home/pi/mema/static/media/
media_directory_url = static/media/
picture_program = /home/pi/mema/take_picture.py
story_program = /home/pi/mema/record_story.py
video_program = /home/pi/mema/record_video.py

# prints lots of stuff on stdout
# time to reload rhasspy docker container tunable
rhasspy_reload = 10

#FIXME: logging used now: into deb like directory structure
debug = True
logfile_name = var/spool/mema3.log

# set to false, to leave things unlabelled etc., since currently external service
#FIXME: whisper.cpp soon set to false, to leave things unlabelled etc., since currently external service
use_external_ai = True

#FIXME: now uses libcamera this is about the simplest set of options
picture_command = libcamera-jpeg --nopreview -o

## --- problematic video section --- ##
# this doesn't do sound currently, need to recompile ffmpeg or move to cvlc?
# pi video
video_command = raspivid -o - -t 60000 -ex night -br 50 -w 1920 -h 1080 -rot 279 -fps 8 | sudo ffmpeg -nostats -loglevel 0 -r 8 -i - -y -vcodec copy
# laptop video, untested 8/11/2022
# video_command = nice cvlc v4l2:// :input-slave=alsa:// :v4l-vdev="/dev/video0"1:v4l-norm=3 :v4l-frequency=-1 :v4l-caching=300 :v4l-chroma="" :v4l-fps=-1.000000 :v4l-samplerate=44100 :v4l-channel=0 :v4l-tuner=-1 :v4l-audio=2 :v4l-stereo :v4l-width=480 :v4l-height=360 :v4l-brightness=-1 :v4l-colour=-1 :v4l-hue=-1 :v4l-contrast=-1 :no-v4l-mjpeg :gain=8 :v4l-decimation=1 :v4l-quality=100 --sout="#transcode{vcodec=theo,vb=2000,fps=12,scale=0.67,acodec=vorb,ab=90,channels=1,samplerate=44100}:duplicate{dst=display,dst=standard{access=file,mux=ogg, dst=file_name}}" --run-time 30 --stop-time=30 vlc://quit

#video_command = streamer -q -c /dev/video0 -f rgb24 -r 3 -t video_maximum -o tmp_file_name
#video_command = ffmpeg -f alsa -i hw:0 -ac 1 -i /dev/video0 -t video_maximum tmp_file_name
#was -ac l: removed input is mono
# ffmpeg -f pulse -ac 2 -i default -f v4l2 -i /dev/video0 -t 00:00:20 -vcodec libx264 record.mp4

ffmpeg_command = ffmpeg -i file_name -c:v libx265 -x265-params lossless=1 -c:a libfdk_aac -b:a 128k -y output_file
# ffmpeg -t 60 -f video4linux2 -input_format mjpeg -i /dev/video0 -c:v libx264 -strict -2 outputs.mp4

# three minutes for testing, but usually we kill it
video_maximum = 30
# specific to vlc until method found to stop videorecording
kill_video_command = killall -s 9 vlc
# changed to libcamera 12/12/2022
video_command = libcamera-vid --nopreview -t video_maximum -o true_file_name
#FIXME: thirty secs for testing, this is milliseconds, kill button?
video_maximum = 30000
#FIXME: needs testing until method found to stop videorecording
kill_video_command = killall -s 9 libcamera-vid

# --- audio recording section --- ##
# specific to laptop hardware, also 30 seconds only for testing
# record_command = arecord -q -f cd -c 2 -D hw:0,0 --duration 30
record_command = arecord -t raw -r 16000 -f S16_LE -c 1
#record_command = arecord -q -f cd -c 2 -D hw:0,0 --duration 30

# laptop record that is whisper.cpp compatible, to be modified for pi, mimic3 ?
#arecord -q -f S16_LE -r 16000 --device=plughw:1,0 --duration 30 example.wav
# arecord -t raw -r 16000 -f S16_LE -c 1 # this is the rhasspy setting

record_command = arecord -q -c 2 -f S16_LE -r 16000 -Dhw:3 --duration
# record maximum in seconds
audio_maximum = 30

#pi record using voice bonnet
# record_command = arecord -f cd -c 2 -D plug:dsnooped --duration 30
#record_command = arecord -f cd -c 2 -D plug:dsnooped --duration 30

#FIXME: label videos, needs work and uses external AI
label_program = ~/mema/label_video.py

label_program = /home/pi/mema/label_video.py

#FIXME: this is problematic, replace with jaro
xdg_open_command = handlr launch x-scheme-handler/http -- http://localhost:8000/memories.html
#xdg_open_command = /home/hbarnard/projects/mema/browser.py
xdg_search_open = xdg-open https://google.com?q=mema

keyword_slot_file = ~/.config/rhasspy/profiles/en/slots/keywords

intent_server = http://localhost:8000
confidence = 0.98

# voice recognition confidence
confidence = 0.98

rhasspy_main = http://localhost:12101
mimic3 = http://localhost:59125
Expand All @@ -70,17 +69,24 @@ language = en
[en_prompts]
sorry = I_cannot_find_that_sorry
not_understood = Sorry_I_cannot_understand_that
start_record = starting to record wait for light
start_video = starting to video wait for light
end_record = finished recording starting to transcribe
end_video = finished recording video
end_transcription = finished transcription
taking_picture = taking picture now
trying_caption = trying to caption picture, please wait a moment
start_record = starting_to_record_wait_for_light
start_video = starting_to_video_wait_for_light
end_record = finished_recording_starting_to_transcribe
end_video = finished_recording_video
end_transcription = finished_transcription
taking_picture = taking_picture_now
trying_caption = trying_to_caption_picture_please_wait_a_moment
not_video = Sorry_this_is_not_a_video
didnt_get = Sorry_no_transcription try again
didnt_get = Sorry_no_transcription_try_again
nope = I'm_sorry_Dave_I'm_afraid_I_can't_do_that
ok_then = OK_then
done = Done and dusted
done = Done_and_dusted
what_kind = What_kind_of_pie_would_you_like?
#FIXME: should be [literals][en] as above
[en_literals]
unlabelled_video = unlabelled video recording
unlabelled_picture = unlablled still image
unlabelled_audio = unlabelled audio recording
22 changes: 16 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,40 @@ echo '*------------------------------------------------------------------------
echo 'making media directories'
echo '*-------------------------------------------------------------------------------*'

mkdir static/media/mos
mkdir static/media/tmp
mkdir static/media/rec
mkdir static/media/vid
mkdir static/media/pic
mkdir -p static/media/mos
mkdir -p static/media/tmp
mkdir -p static/media/rec
mkdir -p static/media/vid
mkdir -p static/media/pic

echo '*-------------------------------------------------------------------------------*'
echo 'installing packages'
echo '*-------------------------------------------------------------------------------*'
# may not need some of these
apt install python3-pip
apt install python3-numpy
apt install python3-pycurl
apt install python3-matplotlib python3-tk
apt install mosquitto mosquitto-dev
apt install sqlite3
apt install cmake
# may or may not need this for sample conversion
# this is to enable the xdg-open replacement jaro
apt-get install guile-2.2
# audiovisual section
apt install ffmpeg
apt install libcamera-apps
apt install pulseaudio
apt install vlc
# docker
sudo apt install docker.io
echo '*-------------------------------------------------------------------------------*'
echo 'installing mema3'
echo 'install python3 packages, make take a while'
echo '*-------------------------------------------------------------------------------*'
sudo -H pip install -r requirements.txt
#FIXME: voice bonnet stuff: not happy about this, does tons of 'other stuff' as well!
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo python3 raspi-blinka.py
echo '*-------------------------------------------------------------------------------*'
echo 'installing intent server service'
cp etc/systemd/intent_server.service /etc/systemd/system/
Expand Down
Loading

0 comments on commit eee0391

Please sign in to comment.