File size: 1,484 Bytes
cbbb792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import os
from dataclasses import dataclass
from typing import Any


def _get_int(name: str, default: int) -> int:
    val = os.getenv(name)
    if val is None:
        return default
    try:
        return int(val)
    except ValueError:
        return default


def _get_bool(name: str, default: bool) -> bool:
    val = os.getenv(name)
    if val is None:
        return default
    val_lower = val.lower().strip()
    if val_lower in {"1", "true", "yes", "on"}:
        return True
    if val_lower in {"0", "false", "no", "off"}:
        return False
    return default


@dataclass(frozen=True)
class Config:
    chunk_ms: int = 160
    voice_enable: bool = False
    video_max_fps: int = 10
    metrics_fps_window: int = 30

    @staticmethod
    def load() -> "Config":
        return Config(
            chunk_ms=_get_int("MIRAGE_CHUNK_MS", 160),
            voice_enable=_get_bool("MIRAGE_VOICE_ENABLE", False),
            video_max_fps=_get_int("MIRAGE_VIDEO_MAX_FPS", 10),
            metrics_fps_window=_get_int("MIRAGE_METRICS_FPS_WINDOW", 30),
        )

    def as_dict(self) -> dict[str, Any]:  # JSON-friendly
        return {
            "chunk_ms": self.chunk_ms,
            "voice_enable": self.voice_enable,
            "video_max_fps": self.video_max_fps,
            "metrics_fps_window": self.metrics_fps_window,
        }


# Eagerly loaded singleton pattern (can be reloaded manually if needed)
config = Config.load()