feat: add microphone field and save_config to Config

This commit is contained in:
2026-04-10 21:01:08 +02:00
parent 3a938ca35b
commit 1637314c1d
2 changed files with 48 additions and 0 deletions
+19
View File
@@ -25,6 +25,7 @@ class Config:
sample_rate: int = 16000
channels: int = 1
min_duration: float = 0.5
microphone: str = ""
def load_config(path: Path = DEFAULT_CONFIG_PATH) -> Config:
@@ -56,5 +57,23 @@ def load_config(path: Path = DEFAULT_CONFIG_PATH) -> Config:
config.channels = audio_section["channels"]
if "min_duration" in audio_section:
config.min_duration = audio_section["min_duration"]
if "device" in audio_section:
config.microphone = audio_section["device"]
return config
def save_config(config: Config, path: Path = DEFAULT_CONFIG_PATH) -> None:
"""Schreibt Config als TOML-Datei. Erstellt Verzeichnisse bei Bedarf."""
path.parent.mkdir(parents=True, exist_ok=True)
content = (
f'[hotkey]\nkey = "{config.hotkey}"\n\n'
f'[whisper]\nmodel = "{config.whisper_model}"\n'
f'language = "{config.language}"\n'
f'compute_type = "{config.compute_type}"\n\n'
f'[audio]\nsample_rate = {config.sample_rate}\n'
f'channels = {config.channels}\n'
f'min_duration = {config.min_duration}\n'
f'device = "{config.microphone}"\n'
)
path.write_text(content, encoding="utf-8")