-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
40 lines (28 loc) · 1.07 KB
/
worker.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
from spleeter.separator import Separator
import logging
import zmq
logging.basicConfig()
log = logging.getLogger("soundpicker-worker")
log.setLevel(logging.INFO)
def process(source_file, target_dir, separator_type):
separator = separators[separator_type]
separator.separate_to_file(source_file, target_dir)
with open(f"{target_dir}/SUCCESS", "w") as f:
pass
def worker():
log.info("Initializing receiver...")
zmq_context = zmq.Context()
zmq_receiver = zmq_context.socket(zmq.PULL)
zmq_receiver.connect("tcp://127.0.0.1:5557")
while True:
payload = zmq_receiver.recv_json()
log.info(f"Received request: {payload}")
process(payload['source_file'], payload['target_dir'], payload['split_type'])
if __name__ == '__main__':
global separators
log.info("Initializing separators...")
separators = {}
separators['spleeter:2stems'] = Separator('spleeter:2stems')
separators['spleeter:4stems'] = Separator('spleeter:4stems')
separators['spleeter:5stems'] = Separator('spleeter:5stems')
worker()