feat(config): pause_media_during_recording-Flag
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+24
-1
@@ -3,7 +3,7 @@ from unittest.mock import patch
|
|||||||
import os
|
import os
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
||||||
from whisper_local.config import Config, load_config
|
from whisper_local.config import Config, load_config, save_config
|
||||||
|
|
||||||
|
|
||||||
class TestConfigDefaults:
|
class TestConfigDefaults:
|
||||||
@@ -113,3 +113,26 @@ class TestSaveConfig:
|
|||||||
save_config(config, path)
|
save_config(config, path)
|
||||||
loaded = load_config(path)
|
loaded = load_config(path)
|
||||||
assert loaded.microphone == 'USB "Pro" Mic'
|
assert loaded.microphone == 'USB "Pro" Mic'
|
||||||
|
|
||||||
|
|
||||||
|
class TestPauseMediaDuringRecording:
|
||||||
|
def test_default_pause_media_during_recording_is_true(self):
|
||||||
|
config = Config()
|
||||||
|
assert config.pause_media_during_recording is True
|
||||||
|
|
||||||
|
def test_load_config_reads_pause_media_false(self, tmp_path: Path):
|
||||||
|
cfg_path = tmp_path / "config.toml"
|
||||||
|
cfg_path.write_text("[media]\npause_during_recording = false\n", encoding="utf-8")
|
||||||
|
|
||||||
|
config = load_config(cfg_path)
|
||||||
|
|
||||||
|
assert config.pause_media_during_recording is False
|
||||||
|
|
||||||
|
def test_save_config_roundtrip_preserves_pause_media(self, tmp_path: Path):
|
||||||
|
cfg_path = tmp_path / "config.toml"
|
||||||
|
original = Config(pause_media_during_recording=False)
|
||||||
|
|
||||||
|
save_config(original, cfg_path)
|
||||||
|
loaded = load_config(cfg_path)
|
||||||
|
|
||||||
|
assert loaded.pause_media_during_recording is False
|
||||||
|
|||||||
+10
-1
@@ -26,6 +26,7 @@ class Config:
|
|||||||
channels: int = 1
|
channels: int = 1
|
||||||
min_duration: float = 0.5
|
min_duration: float = 0.5
|
||||||
microphone: str = ""
|
microphone: str = ""
|
||||||
|
pause_media_during_recording: bool = True
|
||||||
|
|
||||||
|
|
||||||
def load_config(path: Path = DEFAULT_CONFIG_PATH) -> Config:
|
def load_config(path: Path = DEFAULT_CONFIG_PATH) -> Config:
|
||||||
@@ -60,6 +61,12 @@ def load_config(path: Path = DEFAULT_CONFIG_PATH) -> Config:
|
|||||||
if "device" in audio_section:
|
if "device" in audio_section:
|
||||||
config.microphone = audio_section["device"]
|
config.microphone = audio_section["device"]
|
||||||
|
|
||||||
|
media_section = data.get("media", {})
|
||||||
|
if "pause_during_recording" in media_section:
|
||||||
|
config.pause_media_during_recording = bool(
|
||||||
|
media_section["pause_during_recording"]
|
||||||
|
)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
@@ -71,6 +78,7 @@ def _toml_str(value: str) -> str:
|
|||||||
def save_config(config: Config, path: Path = DEFAULT_CONFIG_PATH) -> None:
|
def save_config(config: Config, path: Path = DEFAULT_CONFIG_PATH) -> None:
|
||||||
"""Schreibt Config als TOML-Datei. Erstellt Verzeichnisse bei Bedarf."""
|
"""Schreibt Config als TOML-Datei. Erstellt Verzeichnisse bei Bedarf."""
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
pause_media_str = "true" if config.pause_media_during_recording else "false"
|
||||||
content = (
|
content = (
|
||||||
f'[hotkey]\nkey = "{_toml_str(config.hotkey)}"\n\n'
|
f'[hotkey]\nkey = "{_toml_str(config.hotkey)}"\n\n'
|
||||||
f'[whisper]\nmodel = "{_toml_str(config.whisper_model)}"\n'
|
f'[whisper]\nmodel = "{_toml_str(config.whisper_model)}"\n'
|
||||||
@@ -79,6 +87,7 @@ def save_config(config: Config, path: Path = DEFAULT_CONFIG_PATH) -> None:
|
|||||||
f'[audio]\nsample_rate = {config.sample_rate}\n'
|
f'[audio]\nsample_rate = {config.sample_rate}\n'
|
||||||
f'channels = {config.channels}\n'
|
f'channels = {config.channels}\n'
|
||||||
f'min_duration = {config.min_duration}\n'
|
f'min_duration = {config.min_duration}\n'
|
||||||
f'device = "{_toml_str(config.microphone)}"\n'
|
f'device = "{_toml_str(config.microphone)}"\n\n'
|
||||||
|
f'[media]\npause_during_recording = {pause_media_str}\n'
|
||||||
)
|
)
|
||||||
path.write_text(content, encoding="utf-8")
|
path.write_text(content, encoding="utf-8")
|
||||||
|
|||||||
Reference in New Issue
Block a user