-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_eel.py
More file actions
133 lines (110 loc) · 3.01 KB
/
main_eel.py
File metadata and controls
133 lines (110 loc) · 3.01 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import eel
import threading
import vtt_module as vt
import tts_module as tt
import utils
import json
import os
import keyboard
import sys
import audio_engine as au
log_path= "debug.log"
sys.stdout= open(log_path, 'w', encoding='utf-8', buffering=1)
sys.stderr= open(log_path, 'w', encoding='utf-8', buffering=1)
print("--- [DEBUG] Session Started ---")
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
eel.init(resource_path('web'))
CONFIG_FILE = "user_config.json"
default_config = {
"mic": 0,
"voice" : 0,
"lang": "en",
"volume": 50,
"sensitivity": 20,
"hotkey": "f9",
"model_size": "small"
}
app_config = default_config.copy()
def load_config():
global app_config
if os.path.exists(CONFIG_FILE):
try:
with open(CONFIG_FILE, 'r') as f:
loaded = json.load(f)
app_config.update(loaded)
except: pass
def save_config():
try:
with open(CONFIG_FILE, 'w') as f:
json.dump(app_config, f, indent=4)
except: pass
load_config()
active_stream = False
def toggle_stream():
global active_stream
if active_stream:
stop_stream()
eel.js_trigger_stop()
else:
start_stream()
def set_hotkey(hotkey_str):
try:
keyboard.unhook_all_hotkeys()
except AttributeError:
pass
except Exception as e:
print(f"--- [WARN] Error while cleaning hotkeys: {e} ---")
try:
keyboard.add_hotkey(hotkey_str, toggle_stream)
print(f"--- [HOTKEY] Activated: {hotkey_str} ---")
except Exception as e:
print(f"--- [ERROR] Can't asign hotkey: '{hotkey_str}': {e} ---")
set_hotkey(app_config["hotkey"])
@eel.expose
def update_config(key, value):
print(f"[UI] Config {key}: {value}")
val = int(value) if str(value).isdigit() else value
app_config[key] = val
save_config()
@eel.expose
def update_hotkey(hotkey_str):
try:
set_hotkey(hotkey_str)
app_config["hotkey"] = hotkey_str
save_config()
return True
except: return False
@eel.expose
def start_stream():
global active_stream
if active_stream: return
active_stream = True
t = threading.Thread(
target=au.run_engine,
args=(lambda: active_stream, lambda: app_config),
daemon=True
)
t.start()
@eel.expose
def stop_stream():
global active_stream
active_stream = False
@eel.expose
def get_init_data():
return {
"mics": vt.select_mic(),
"voices": tt.list_voices(),
"languages": utils.INPUT_LANGUAGES,
"config": app_config
}
if sys.platform in ['win32', 'cygwin']: browser = 'edge'
else: browser = 'chrome'
try:
eel.start('index.html', size=(680, 980), mode=browser, port=0)
except EnvironmentError:
eel.start('index.html', size=(680, 980), mode='default', port=0)