forked from hbarnard/mema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
record_video.py
executable file
·87 lines (67 loc) · 2.93 KB
/
record_video.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
from time import sleep
import board
#FIXME: get rid, seems to be incompatilities: import requests
import datetime
import subprocess
from pathlib import Path
import os
from configobj import ConfigObj
import logging
import re
import memalib.mema_utility as mu
# main script
def main():
dots = {}
config = ConfigObj('etc/mema.ini')
logging.basicConfig(filename=config['main']['logfile_name'], format='%(asctime)s %(message)s', encoding='utf-8', level=logging.DEBUG)
# convenience for separating Pi and a random laptop
pi = False
#FIXME: mema.ini produces strings! also no test on system name now, unreliable
if config['main']['pi'] == 'yes' :
pi = True
if pi:
import board
# coloured LEDS on front of voice bonnet, for primitive feedback
from digitalio import DigitalInOut, Direction, Pull
import adafruit_dotstar
DOTSTAR_DATA = board.D5
DOTSTAR_CLOCK = board.D6
dots = adafruit_dotstar.DotStar(DOTSTAR_CLOCK, DOTSTAR_DATA, 3, brightness=0.2)
mu.curl_speak(config['en_prompts']['start_video'])
#FIXME: Actually no need to do this currently, since there's no audio!
#logging.debug('unload docker')
unix_time = mu.docker_control('stop', 'mema_rhasspy')
#FIXME: libcamera on pi, no audio currently, see extensive web commentary
true_file_name = str(unix_time) + ".mp4"
if pi:
dots[0] = (255,0,0)
video_command = config['main']['video_command']
true_file_path = config['main']['media_directory'] + "vid/" + true_file_name
media_path = config['main']['media_directory_url'] + "vid/" + true_file_name
try:
#FIXME: may need adjustment on laptop direct record as silent mp4
rev_command = re.sub(r"true_file_name", true_file_path, video_command)
revised_command = re.sub(r"video_maximum", config['main']['video_maximum'], rev_command)
logging.debug('revised command: ' + revised_command)
subprocess.call(revised_command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except subprocess.CalledProcessError as e:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
if pi:
dots[0] = (0,0,255)
logging.debug('reload docker start')
unix_time = mu.docker_control('start', 'mema_rhasspy')
logging.debug('reload docker end')
sleep(int(config['main']['rhasspy_reload'])) # give mema_rhasspy time to reload!
mu.curl_speak(config['en_prompts']['end_video'])
mu.curl_speak(config['en_prompts']['done'])
# done, feedback, stop blinking lights
if pi:
dots[0] = (255,0,0) # green
sleep(2)
dots.deinit()
text = config['en_literals']['unlabelled_video']
# return result and file path to intent server
print(text + "|" + media_path)
if __name__ == '__main__':
main()