-
Notifications
You must be signed in to change notification settings - Fork 1
/
stereo_recording.py
64 lines (54 loc) · 1.87 KB
/
stereo_recording.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
# Helper functions to start/stop stereo recording of sessions
# import jack
import psutil
import subprocess
from datetime import datetime
class StereoRecording(object):
"""Record stereo mix"""
def __init__(self, recording_path_prefix, dry_run):
super(StereoRecording, self).__init__()
self.recording_path_prefix = recording_path_prefix
self.dry_run = dry_run
def get_time_string(self):
return datetime.now().strftime("%Y_%m_%d_%H%M")
def get_filename_prefix(self):
time = self.get_time_string()
return self.recording_path_prefix + time + "-"
def generate_subprocess_cmd(self):
return [
"jack_capture",
"--filename-prefix",
self.get_filename_prefix(),
"-S",
"--channels",
"2",
"--port",
"darkice*",
"--daemon",
]
def darkice_process(self):
for proc in psutil.process_iter(["pid", "name", "username", "cmdline"]):
if proc.name() == "jack_capture":
return proc
if proc.cmdline()[2] == "darkice-":
return proc
def start(self):
if self.dry_run:
print("Start recording if not running already")
return
if self.darkice_process():
print("already started!")
else:
print("starting...")
mysub = subprocess.Popen(self.generate_subprocess_cmd())
print("Recording started, process num: ", mysub.pid)
def stop(self):
if self.dry_run:
print("Stop recording if not stopped already")
return
myprocess = self.darkice_process()
if not myprocess:
print("No recording running, apparently!")
return
print("Stopping recording process num:", myprocess.pid)
myprocess.kill()