-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
108 lines (75 loc) · 2.59 KB
/
Copy pathmain.py
File metadata and controls
108 lines (75 loc) · 2.59 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
main.py
-------
Main file
"""
from __future__ import annotations
import argparse
import logging
import sys
from pathlib import Path
import yaml
from dotenv import load_dotenv
from voice_assistant.voice_assistant import VoiceAssistant
from parse.parse_file import parse_file
load_dotenv()
def setup_logging(cfg: dict):
log_cfg = cfg.get("logging", {})
log_file = log_cfg.get("file", "assistant.log")
formatter = logging.Formatter(
"%(asctime)s "
"[%(levelname)s] "
"%(name)s: %(message)s"
)
# Terminal: WARNING and higher only
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.WARNING)
console_handler.setFormatter(formatter)
handlers = [console_handler]
# File : All logs
if log_file:
Path(log_file).parent.mkdir(parents=True, exist_ok=True)
file_handler = logging.FileHandler(
log_file,
encoding="utf-8"
)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
handlers.append(file_handler)
# The root logger must accept all levels
logging.basicConfig(
level=logging.DEBUG,
handlers=handlers,
)
def main():
parser = argparse.ArgumentParser(description="Local voice assistant")
parser.add_argument("--config", default="config/config.yaml")
parser.add_argument("--parse", action="store_true", help="Parse the music file")
args = parser.parse_args()
# -------------------------------------------------------------
# Configuration
# -------------------------------------------------------------
with open(args.config, encoding="utf-8") as f:
cfg = yaml.safe_load(f)
# -------------------------------------------------------------
# Parse musique
# -------------------------------------------------------------
if args.parse:
parse_file(cfg["player"]["music_dir"])
return
# -------------------------------------------------------------
# Logging
# -------------------------------------------------------------
setup_logging(cfg)
logger = logging.getLogger("main")
# -------------------------------------------------------------
# Assistant
# -------------------------------------------------------------
logger.info("Creating VoiceAssistant...")
assistant = VoiceAssistant(cfg)
# -------------------------------------------------------------
# Run
# -------------------------------------------------------------
assistant.run()
if __name__ == "__main__":
main()