micforge 1.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- micforge/__init__.py +3 -0
- micforge/__main__.py +4 -0
- micforge/analysis/__init__.py +0 -0
- micforge/analysis/stats.py +133 -0
- micforge/audio/__init__.py +0 -0
- micforge/audio/backend.py +32 -0
- micforge/audio/cues.py +110 -0
- micforge/audio/device_watch.py +237 -0
- micforge/audio/devices.py +160 -0
- micforge/audio/engine.py +746 -0
- micforge/audio/fileio.py +45 -0
- micforge/audio/latency.py +169 -0
- micforge/audio/loopback.py +113 -0
- micforge/audio/metrics.py +134 -0
- micforge/audio/noise_profile.py +250 -0
- micforge/audio/recorder.py +100 -0
- micforge/audio/ring.py +89 -0
- micforge/cli.py +293 -0
- micforge/commands/__init__.py +0 -0
- micforge/commands/calibrate.py +47 -0
- micforge/commands/common.py +69 -0
- micforge/commands/devices_cmd.py +86 -0
- micforge/commands/diagnostics_cmd.py +68 -0
- micforge/commands/doctor.py +127 -0
- micforge/commands/files.py +48 -0
- micforge/commands/help_cmd.py +449 -0
- micforge/commands/latency_test.py +65 -0
- micforge/commands/live.py +321 -0
- micforge/commands/preset_cmd.py +142 -0
- micforge/commands/test_mic.py +98 -0
- micforge/commands/wizard.py +70 -0
- micforge/config.py +279 -0
- micforge/diagnostics.py +308 -0
- micforge/dsp/__init__.py +0 -0
- micforge/dsp/aec.py +388 -0
- micforge/dsp/base.py +30 -0
- micforge/dsp/biquad.py +144 -0
- micforge/dsp/chain.py +153 -0
- micforge/dsp/cofilite.py +427 -0
- micforge/dsp/compressor.py +109 -0
- micforge/dsp/deesser.py +64 -0
- micforge/dsp/denoise.py +181 -0
- micforge/dsp/deverb.py +227 -0
- micforge/dsp/export_cofilite.py +111 -0
- micforge/dsp/gate.py +76 -0
- micforge/dsp/leveler.py +74 -0
- micforge/dsp/proximity.py +164 -0
- micforge/dsp/util.py +80 -0
- micforge/errors.py +25 -0
- micforge/logging_setup.py +25 -0
- micforge/models/cofilite.onnx +0 -0
- micforge/presets.py +284 -0
- micforge/profile_store.py +41 -0
- micforge/ui/__init__.py +0 -0
- micforge/ui/dashboard.py +573 -0
- micforge/ui/hotkeys.py +169 -0
- micforge/ui/keys.py +64 -0
- micforge/ui/report.py +88 -0
- micforge/ui/settings_gui.py +899 -0
- micforge/ui/theme.py +42 -0
- micforge/ui/tray.py +276 -0
- micforge/ui/tuning.py +138 -0
- micforge/ui/widgets.py +109 -0
- micforge/util/autostart.py +56 -0
- micforge-1.3.0.dist-info/METADATA +334 -0
- micforge-1.3.0.dist-info/RECORD +70 -0
- micforge-1.3.0.dist-info/WHEEL +5 -0
- micforge-1.3.0.dist-info/entry_points.txt +2 -0
- micforge-1.3.0.dist-info/licenses/LICENSE +22 -0
- micforge-1.3.0.dist-info/top_level.txt +1 -0
micforge/ui/hotkeys.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""System-wide global hotkeys using non-intrusive pynput hooks.
|
|
2
|
+
|
|
3
|
+
Works while in fullscreen games, Discord, or desktop apps without requiring admin rights.
|
|
4
|
+
Supports Toggle Mute, Push-to-Mute, Push-to-Talk, and Toggle Bypass.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
import threading
|
|
10
|
+
from typing import Callable
|
|
11
|
+
|
|
12
|
+
from ..config import HotkeyConfig
|
|
13
|
+
|
|
14
|
+
log = logging.getLogger("micforge.hotkeys")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def normalize_hotkey_for_pynput(s: str) -> str:
|
|
18
|
+
"""Convert human-friendly hotkey string (e.g. 'ctrl+shift+m') to pynput format ('<ctrl>+<shift>+m')."""
|
|
19
|
+
if not s or not s.strip():
|
|
20
|
+
return ""
|
|
21
|
+
tokens = [t.strip().lower() for t in s.replace(" ", "").split("+") if t.strip()]
|
|
22
|
+
formatted = []
|
|
23
|
+
for t in tokens:
|
|
24
|
+
if t in ("ctrl", "control", "lctrl", "rctrl"):
|
|
25
|
+
formatted.append("<ctrl>")
|
|
26
|
+
elif t in ("shift", "lshift", "rshift"):
|
|
27
|
+
formatted.append("<shift>")
|
|
28
|
+
elif t in ("alt", "lalt", "ralt"):
|
|
29
|
+
formatted.append("<alt>")
|
|
30
|
+
elif t in ("cmd", "win", "windows", "super"):
|
|
31
|
+
formatted.append("<cmd>")
|
|
32
|
+
elif len(t) == 1:
|
|
33
|
+
formatted.append(t)
|
|
34
|
+
else:
|
|
35
|
+
# Special keys like f1..f12, space, etc.
|
|
36
|
+
formatted.append(f"<{t}>")
|
|
37
|
+
return "+".join(formatted)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class GlobalHotkeyManager:
|
|
41
|
+
"""Manages system-wide hotkeys and push-to-talk/push-to-mute listeners."""
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
config: HotkeyConfig,
|
|
46
|
+
*,
|
|
47
|
+
on_toggle_mute: Callable[[], None] | None = None,
|
|
48
|
+
on_set_mute: Callable[[bool], None] | None = None,
|
|
49
|
+
on_toggle_bypass: Callable[[], None] | None = None,
|
|
50
|
+
) -> None:
|
|
51
|
+
self.config = config
|
|
52
|
+
self.on_toggle_mute = on_toggle_mute
|
|
53
|
+
self.on_set_mute = on_set_mute
|
|
54
|
+
self.on_toggle_bypass = on_toggle_bypass
|
|
55
|
+
|
|
56
|
+
self._hotkey_listener = None
|
|
57
|
+
self._ptt_listener = None
|
|
58
|
+
self._running = False
|
|
59
|
+
self._lock = threading.Lock()
|
|
60
|
+
self._ptt_down = False
|
|
61
|
+
self._ptm_down = False
|
|
62
|
+
|
|
63
|
+
def start(self) -> None:
|
|
64
|
+
with self._lock:
|
|
65
|
+
if self._running:
|
|
66
|
+
return
|
|
67
|
+
self._running = True
|
|
68
|
+
self._start_listeners()
|
|
69
|
+
|
|
70
|
+
def stop(self) -> None:
|
|
71
|
+
with self._lock:
|
|
72
|
+
if not self._running:
|
|
73
|
+
return
|
|
74
|
+
self._running = False
|
|
75
|
+
self._stop_listeners()
|
|
76
|
+
|
|
77
|
+
def update_config(self, new_config: HotkeyConfig) -> None:
|
|
78
|
+
"""Update hotkey configuration and rebind listeners dynamically."""
|
|
79
|
+
with self._lock:
|
|
80
|
+
self.config = new_config
|
|
81
|
+
if self._running:
|
|
82
|
+
self._stop_listeners()
|
|
83
|
+
self._start_listeners()
|
|
84
|
+
|
|
85
|
+
def _start_listeners(self) -> None:
|
|
86
|
+
try:
|
|
87
|
+
from pynput import keyboard
|
|
88
|
+
except ImportError:
|
|
89
|
+
log.warning("pynput is not installed; global hotkeys disabled.")
|
|
90
|
+
return
|
|
91
|
+
|
|
92
|
+
# 1. GlobalHotKeys mapping for combinations (Toggle Mute, Toggle Bypass)
|
|
93
|
+
hotkey_map: dict[str, Callable[[], None]] = {}
|
|
94
|
+
if self.config.toggle_mute and self.on_toggle_mute:
|
|
95
|
+
key_str = normalize_hotkey_for_pynput(self.config.toggle_mute)
|
|
96
|
+
if key_str:
|
|
97
|
+
hotkey_map[key_str] = self.on_toggle_mute
|
|
98
|
+
|
|
99
|
+
if self.config.toggle_bypass and self.on_toggle_bypass:
|
|
100
|
+
key_str = normalize_hotkey_for_pynput(self.config.toggle_bypass)
|
|
101
|
+
if key_str:
|
|
102
|
+
hotkey_map[key_str] = self.on_toggle_bypass
|
|
103
|
+
|
|
104
|
+
if hotkey_map:
|
|
105
|
+
try:
|
|
106
|
+
self._hotkey_listener = keyboard.GlobalHotKeys(hotkey_map)
|
|
107
|
+
self._hotkey_listener.daemon = True
|
|
108
|
+
self._hotkey_listener.start()
|
|
109
|
+
log.info("Registered global hotkeys: %s", list(hotkey_map.keys()))
|
|
110
|
+
except Exception as exc: # noqa: BLE001
|
|
111
|
+
log.warning("Failed to register GlobalHotKeys: %s", exc)
|
|
112
|
+
|
|
113
|
+
# 2. Key press/release listener for Push-to-Talk (PTT) and Push-to-Mute (PTM)
|
|
114
|
+
has_ptt = bool(self.config.push_to_talk and self.config.push_to_talk.strip())
|
|
115
|
+
has_ptm = bool(self.config.push_to_mute and self.config.push_to_mute.strip())
|
|
116
|
+
|
|
117
|
+
if (has_ptt or has_ptm) and self.on_set_mute:
|
|
118
|
+
ptt_target = self.config.push_to_talk.strip().lower()
|
|
119
|
+
ptm_target = self.config.push_to_mute.strip().lower()
|
|
120
|
+
|
|
121
|
+
def _get_key_name(key) -> str:
|
|
122
|
+
try:
|
|
123
|
+
if hasattr(key, "char") and key.char:
|
|
124
|
+
return key.char.lower()
|
|
125
|
+
if hasattr(key, "name") and key.name:
|
|
126
|
+
return key.name.lower()
|
|
127
|
+
except Exception: # noqa: BLE001
|
|
128
|
+
pass
|
|
129
|
+
return str(key).lower().replace("key.", "")
|
|
130
|
+
|
|
131
|
+
def _on_press(key):
|
|
132
|
+
kname = _get_key_name(key)
|
|
133
|
+
if has_ptt and kname == ptt_target and not self._ptt_down:
|
|
134
|
+
self._ptt_down = True
|
|
135
|
+
self.on_set_mute(False) # Unmute while pressed
|
|
136
|
+
elif has_ptm and kname == ptm_target and not self._ptm_down:
|
|
137
|
+
self._ptm_down = True
|
|
138
|
+
self.on_set_mute(True) # Mute while pressed
|
|
139
|
+
|
|
140
|
+
def _on_release(key):
|
|
141
|
+
kname = _get_key_name(key)
|
|
142
|
+
if has_ptt and kname == ptt_target and self._ptt_down:
|
|
143
|
+
self._ptt_down = False
|
|
144
|
+
self.on_set_mute(True) # Mute when released
|
|
145
|
+
elif has_ptm and kname == ptm_target and self._ptm_down:
|
|
146
|
+
self._ptm_down = False
|
|
147
|
+
self.on_set_mute(False) # Unmute when released
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
self._ptt_listener = keyboard.Listener(on_press=_on_press, on_release=_on_release)
|
|
151
|
+
self._ptt_listener.daemon = True
|
|
152
|
+
self._ptt_listener.start()
|
|
153
|
+
except Exception as exc: # noqa: BLE001
|
|
154
|
+
log.warning("Failed to register PTT/PTM listener: %s", exc)
|
|
155
|
+
|
|
156
|
+
def _stop_listeners(self) -> None:
|
|
157
|
+
if self._hotkey_listener is not None:
|
|
158
|
+
try:
|
|
159
|
+
self._hotkey_listener.stop()
|
|
160
|
+
except Exception: # noqa: BLE001
|
|
161
|
+
pass
|
|
162
|
+
self._hotkey_listener = None
|
|
163
|
+
if self._ptt_listener is not None:
|
|
164
|
+
try:
|
|
165
|
+
self._ptt_listener.stop()
|
|
166
|
+
except Exception: # noqa: BLE001
|
|
167
|
+
pass
|
|
168
|
+
self._ptt_listener = None
|
|
169
|
+
|
micforge/ui/keys.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Non-blocking single-key input for the live dashboard (POSIX + Windows)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class KeyReader:
|
|
10
|
+
def __init__(self) -> None:
|
|
11
|
+
self.enabled = False
|
|
12
|
+
self._fd: int | None = None
|
|
13
|
+
self._old = None
|
|
14
|
+
|
|
15
|
+
def __enter__(self) -> "KeyReader":
|
|
16
|
+
if not sys.stdin or not sys.stdin.isatty():
|
|
17
|
+
return self
|
|
18
|
+
if os.name == "nt":
|
|
19
|
+
self.enabled = True
|
|
20
|
+
return self
|
|
21
|
+
import termios
|
|
22
|
+
import tty
|
|
23
|
+
|
|
24
|
+
self._fd = sys.stdin.fileno()
|
|
25
|
+
self._old = termios.tcgetattr(self._fd)
|
|
26
|
+
tty.setcbreak(self._fd) # keeps Ctrl+C working
|
|
27
|
+
self.enabled = True
|
|
28
|
+
return self
|
|
29
|
+
|
|
30
|
+
def __exit__(self, *exc: object) -> None:
|
|
31
|
+
if self._fd is not None and self._old is not None:
|
|
32
|
+
import termios
|
|
33
|
+
|
|
34
|
+
termios.tcsetattr(self._fd, termios.TCSADRAIN, self._old)
|
|
35
|
+
|
|
36
|
+
def poll(self, timeout: float = 0.0) -> str | None:
|
|
37
|
+
if not self.enabled:
|
|
38
|
+
time.sleep(timeout)
|
|
39
|
+
return None
|
|
40
|
+
if os.name == "nt":
|
|
41
|
+
import msvcrt
|
|
42
|
+
|
|
43
|
+
end = time.monotonic() + timeout
|
|
44
|
+
while True:
|
|
45
|
+
if msvcrt.kbhit():
|
|
46
|
+
ch = msvcrt.getwch()
|
|
47
|
+
if ch in ("\x00", "\xe0"): # arrow / function key prefix
|
|
48
|
+
msvcrt.getwch()
|
|
49
|
+
return None
|
|
50
|
+
return ch
|
|
51
|
+
if time.monotonic() >= end:
|
|
52
|
+
return None
|
|
53
|
+
time.sleep(0.01)
|
|
54
|
+
import select
|
|
55
|
+
|
|
56
|
+
r, _, _ = select.select([sys.stdin], [], [], timeout)
|
|
57
|
+
if not r:
|
|
58
|
+
return None
|
|
59
|
+
ch = os.read(self._fd, 1).decode(errors="ignore") # type: ignore[arg-type]
|
|
60
|
+
if ch == "\x1b": # swallow escape sequences
|
|
61
|
+
while select.select([sys.stdin], [], [], 0)[0]:
|
|
62
|
+
os.read(self._fd, 1) # type: ignore[arg-type]
|
|
63
|
+
return None
|
|
64
|
+
return ch
|
micforge/ui/report.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Before/after report used by `test`, `process` and `analyze`."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from rich import box
|
|
5
|
+
from rich.console import Group
|
|
6
|
+
from rich.panel import Panel
|
|
7
|
+
from rich.table import Table
|
|
8
|
+
from rich.text import Text
|
|
9
|
+
|
|
10
|
+
from ..analysis.stats import AudioStats, Finding, clarity_label
|
|
11
|
+
from .theme import LEVEL_ICON
|
|
12
|
+
from .widgets import freq_axis, spectrum_rows
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _f(v: float | None, fmt: str = "{:.1f}", unit: str = "") -> str:
|
|
17
|
+
return "-" if v is None else fmt.format(v) + unit
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _delta(a: float | None, b: float | None, better_up: bool) -> Text:
|
|
21
|
+
if a is None or b is None:
|
|
22
|
+
return Text("")
|
|
23
|
+
d = b - a
|
|
24
|
+
if abs(d) < 0.5:
|
|
25
|
+
return Text(f"{d:+.1f}", style="grey50")
|
|
26
|
+
good = (d > 0) == better_up
|
|
27
|
+
return Text(f"{d:+.1f}", style="green" if good else "yellow")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def stats_table(before: AudioStats, after: AudioStats | None = None) -> Table:
|
|
31
|
+
t = Table(box=box.SIMPLE_HEAD, header_style="bold cyan", pad_edge=False)
|
|
32
|
+
t.add_column("metric")
|
|
33
|
+
t.add_column("raw", justify="right")
|
|
34
|
+
if after:
|
|
35
|
+
t.add_column("processed", justify="right")
|
|
36
|
+
t.add_column("Δ", justify="right")
|
|
37
|
+
rows = [
|
|
38
|
+
("peak (dBFS)", before.peak_db, after.peak_db if after else None, None),
|
|
39
|
+
("voice level (dBFS)", before.active_rms_db, after.active_rms_db if after else None, None),
|
|
40
|
+
("noise floor (dBFS)", before.noise_floor_db, after.noise_floor_db if after else None, False),
|
|
41
|
+
("SNR (dB)", before.snr_db, after.snr_db if after else None, True),
|
|
42
|
+
("presence 2.5-8k vs rest (dB)", before.presence_db, after.presence_db if after else None, True),
|
|
43
|
+
("spectral centroid (Hz)", before.centroid_hz, after.centroid_hz if after else None, True),
|
|
44
|
+
]
|
|
45
|
+
for name, a, b, up in rows:
|
|
46
|
+
cells = [name, _f(a, "{:.0f}" if "Hz" in name else "{:.1f}")]
|
|
47
|
+
if after:
|
|
48
|
+
cells.append(_f(b, "{:.0f}" if "Hz" in name else "{:.1f}"))
|
|
49
|
+
cells.append(_delta(a, b, up) if up is not None else Text("")) # type: ignore[arg-type]
|
|
50
|
+
t.add_row(*cells)
|
|
51
|
+
clar = [clarity_label(before.presence_db)] + ([clarity_label(after.presence_db)] if after else [])
|
|
52
|
+
t.add_row("clarity (heuristic)", *[Text(c, style="bold") for c in clar], *([Text("")] if after else []))
|
|
53
|
+
clips = [str(before.clip_samples)] + ([str(after.clip_samples)] if after else [])
|
|
54
|
+
t.add_row("clipped samples", *clips, *([Text("")] if after else []))
|
|
55
|
+
return t
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def findings_panel(findings: list[Finding]) -> Panel:
|
|
59
|
+
lines = Text()
|
|
60
|
+
for f in findings:
|
|
61
|
+
lines.append_text(Text.from_markup(f"{LEVEL_ICON[f.level]} "))
|
|
62
|
+
lines.append(f.text + "\n")
|
|
63
|
+
lines.rstrip()
|
|
64
|
+
return Panel(lines, title="diagnosis", title_align="left", border_style="grey37", box=box.ROUNDED)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def spectrum_compare(before: np.ndarray, after: np.ndarray, f_lo: float = 60.0, f_hi: float = 16000.0) -> Panel:
|
|
68
|
+
ref = float(np.max(before))
|
|
69
|
+
lo, hi = ref - 60.0, ref # same scale for both so the shapes are comparable
|
|
70
|
+
n = before.shape[0]
|
|
71
|
+
tbl = Table.grid(padding=(0, 2))
|
|
72
|
+
tbl.add_column()
|
|
73
|
+
tbl.add_column()
|
|
74
|
+
tbl.add_row(Text("raw", style="grey70"), Text("processed", style="bold green"))
|
|
75
|
+
for a, b in zip(spectrum_rows(before, 5, 1, lo, hi, "blue"), spectrum_rows(after, 5, 1, lo, hi, "green")):
|
|
76
|
+
tbl.add_row(a, b)
|
|
77
|
+
ax = freq_axis(n, 1, f_lo, f_hi)
|
|
78
|
+
tbl.add_row(ax, ax)
|
|
79
|
+
return Panel(tbl, title="long-term spectrum", title_align="left", border_style="grey37", box=box.ROUNDED)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def full_report(before: AudioStats, after: AudioStats | None, b_bands=None, a_bands=None, findings=None) -> Group:
|
|
83
|
+
parts = [stats_table(before, after)]
|
|
84
|
+
if b_bands is not None and a_bands is not None:
|
|
85
|
+
parts.append(spectrum_compare(b_bands, a_bands))
|
|
86
|
+
if findings:
|
|
87
|
+
parts.append(findings_panel(findings))
|
|
88
|
+
return Group(*parts)
|