-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
68 lines (55 loc) · 2.64 KB
/
main.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
from components.configs_reader import read_configs
from components.watchdog_daemon import create_observer
from components.noisereducer import cleaner_worker
from components.transcriber import transcriber_worker
from components.logs_writer import configure_loger
import multiprocessing as mp
import logging
APP_CONFIGS = read_configs() # read and validate configuration file
if __name__ == '__main__':
logger = configure_loger(APP_CONFIGS)
# variables
logs_queue = mp.Queue(-1)
queue_to_cleaning = mp.Queue(-1)
queue_to_transcribe = mp.Queue(-1)
# subprocesses
# 1) watchdog with queue to cleaning
watchdog_cleaner_proc = mp.Process(target= create_observer, args= (APP_CONFIGS.working_dir,\
queue_to_cleaning))
watchdog_cleaner_proc.daemon= True
watchdog_cleaner_proc.start()
##watchdog_proc.join()
## 2) cleaner
cleaner = mp.Process(target= cleaner_worker, args= (APP_CONFIGS,\
queue_to_cleaning,\
logs_queue))
cleaner.daemon= True
cleaner.start()
# 3) watchdog with queue to transcribation
watchdog_transcribe_proc = mp.Process(target= create_observer, args= (APP_CONFIGS.clean_audio_dir,\
queue_to_transcribe))
watchdog_transcribe_proc.daemon= True
watchdog_transcribe_proc.start()
# 4) Whisper transcriber implementation (multiple GPU support)
transcriber_proc = []
for device in APP_CONFIGS.devices:
t_proc = mp.Process(target= transcriber_worker, args= (APP_CONFIGS,\
queue_to_transcribe,\
logs_queue,\
device))
t_proc.daemon= True
transcriber_proc.append(t_proc)
t_proc.start()
logging.LoggerAdapter(logger, {'service_name': 'MAIN'}).info('Startup success')
try:
while True:
message= logs_queue.get().split('|')
logging.LoggerAdapter(logger, {'service_name': f'{message[1]}'}).info(message[0])
pass
except KeyboardInterrupt:
watchdog_cleaner_proc.terminate()
cleaner.terminate()
watchdog_transcribe_proc.terminate()
for proc in transcriber_proc:
proc.terminate()
logging.LoggerAdapter(logger, {'service_name': 'MAIN'}).info('All processes terminated')