aman/src/config_ui_audio.py
Thales Maciel c6fc61c885
Some checks failed
ci / Unit Matrix (3.10) (push) Has been cancelled
ci / Unit Matrix (3.11) (push) Has been cancelled
ci / Unit Matrix (3.12) (push) Has been cancelled
ci / Portable Ubuntu Smoke (push) Has been cancelled
ci / Package Artifacts (push) Has been cancelled
Normalize native dependency ownership and split config UI
Make distro packages the single source of truth for GTK/X11 Python bindings instead of advertising them as wheel-managed runtime dependencies. Update the uv, CI, and packaging workflows to use system site packages, regenerate uv.lock, and keep portable and Arch metadata aligned with that contract.

Pull runtime policy, audio probing, and page builders out of config_ui.py so the settings window becomes a coordinator instead of a single large mixed-concern module. Rename the config serialization and logging helpers, and stop startup logging from exposing raw vocabulary entries or custom model paths.

Remove stale helper aliases and add regression coverage for safe startup logging, packaging metadata and module drift, portable requirements, and the extracted audio helper behavior.

Validated with uv lock, python3 -m compileall -q src tests, python3 -m unittest discover -s tests -p 'test_*.py', make build, and make package-arch.
2026-03-15 11:27:54 -03:00

52 lines
1.3 KiB
Python

from __future__ import annotations
import time
from dataclasses import dataclass
from typing import Any
from recorder import (
list_input_devices,
resolve_input_device,
start_recording,
stop_recording,
)
@dataclass(frozen=True)
class MicrophoneTestResult:
ok: bool
message: str
class AudioSettingsService:
def list_input_devices(self) -> list[dict[str, Any]]:
return list_input_devices()
def resolve_input_device(self, input_spec: str | int | None) -> int | None:
return resolve_input_device(input_spec)
def test_microphone(
self,
input_spec: str | int | None,
*,
duration_sec: float = 0.35,
) -> MicrophoneTestResult:
try:
stream, record = start_recording(input_spec)
time.sleep(duration_sec)
audio = stop_recording(stream, record)
except Exception as exc:
return MicrophoneTestResult(
ok=False,
message=f"Microphone test failed: {exc}",
)
if getattr(audio, "size", 0) > 0:
return MicrophoneTestResult(
ok=True,
message="Microphone test successful.",
)
return MicrophoneTestResult(
ok=False,
message="No audio captured. Try another device.",
)