field_registry.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. # -*- coding: utf-8 -*-
  2. """
  3. Feld-Registry fuer typ-spezifische Config-Editoren.
  4. Definiert Metadaten pro Config-Feld: Editor-Typ, Auswahlmoeglichkeiten,
  5. Wertebereiche und dynamische Quellen fuer Optionen.
  6. """
  7. from __future__ import annotations
  8. from dataclasses import dataclass, field
  9. from enum import Enum
  10. class EditorType(str, Enum):
  11. """Unterstuetzte Editor-Typen fuer Config-Felder."""
  12. SELECT = "select"
  13. BOOL = "bool"
  14. NUMBER_INT = "number_int"
  15. NUMBER_FLOAT = "number_float"
  16. TEXT = "text"
  17. IP_ADDRESS = "ip_address"
  18. PATH = "path"
  19. LIST_SELECT = "list_select"
  20. LIST_TEXT = "list_text"
  21. READONLY = "readonly"
  22. @dataclass
  23. class FieldMeta:
  24. """
  25. Metadaten fuer ein einzelnes Config-Feld.
  26. Bestimmt welcher Editor-Typ verwendet wird, welche
  27. Auswahlmoeglichkeiten existieren und wie validiert wird.
  28. """
  29. editor: EditorType
  30. choices: list[tuple[str, str]] | None = None
  31. min_value: float | None = None
  32. max_value: float | None = None
  33. step: float | None = None
  34. placeholder: str = ""
  35. requires_restart: bool = False
  36. dynamic_source: str | None = None
  37. hint: str = ""
  38. # --- Log-Level Auswahl (gemeinsam genutzt) ---
  39. _LOG_LEVEL_CHOICES: list[tuple[str, str]] = [
  40. ("DEBUG", "DEBUG"),
  41. ("INFO", "INFO"),
  42. ("WARNING", "WARNING"),
  43. ("ERROR", "ERROR"),
  44. ("CRITICAL", "CRITICAL"),
  45. ]
  46. # --- Audio Sample-Rate Auswahl ---
  47. _SAMPLE_RATE_CHOICES: list[tuple[str, str]] = [
  48. ("8000", "8000 Hz"),
  49. ("16000", "16000 Hz"),
  50. ("22050", "22050 Hz"),
  51. ("44100", "44100 Hz"),
  52. ("48000", "48000 Hz"),
  53. ]
  54. # --- Audio Channels Auswahl ---
  55. _CHANNELS_CHOICES: list[tuple[str, str]] = [
  56. ("1", "Mono"),
  57. ("2", "Stereo"),
  58. ]
  59. # --- Audio Bit-Depth Auswahl ---
  60. _BIT_DEPTH_CHOICES: list[tuple[str, str]] = [
  61. ("16", "16 Bit"),
  62. ("24", "24 Bit"),
  63. ("32", "32 Bit"),
  64. ]
  65. # --- Notification Auswahl ---
  66. _NOTIFICATION_CHOICES: list[tuple[str, str]] = [
  67. ("0", "Keine"),
  68. ("1", "TTS"),
  69. ("2", "Wave-Datei"),
  70. ("3", "TTS + Wave"),
  71. ]
  72. # --- STT-Korrektur Layer Auswahl ---
  73. _STT_LAYER_CHOICES: list[tuple[str, str]] = [
  74. ("symspell", "SymSpell"),
  75. ("phonetic", "Phonetisch"),
  76. ("kenlm", "KenLM"),
  77. ("jamspell", "JamSpell"),
  78. ("hunspell", "Hunspell"),
  79. ("languagetool", "LanguageTool"),
  80. ]
  81. # --- Port-Feld Defaults ---
  82. _PORT_META = FieldMeta(
  83. editor=EditorType.NUMBER_INT,
  84. min_value=1024,
  85. max_value=65535,
  86. requires_restart=True,
  87. hint="Port (1024-65535)",
  88. )
  89. def _port(hint: str = "") -> FieldMeta:
  90. """Erzeugt FieldMeta fuer ein Port-Feld."""
  91. return FieldMeta(
  92. editor=EditorType.NUMBER_INT,
  93. min_value=1024,
  94. max_value=65535,
  95. requires_restart=True,
  96. hint=hint or "Port (1024-65535)",
  97. )
  98. def build_server_registry() -> dict[str, FieldMeta]:
  99. """Baut die Feld-Registry fuer Server-Konfiguration."""
  100. return {
  101. # --- Logging ---
  102. "logging.level": FieldMeta(
  103. editor=EditorType.SELECT,
  104. choices=_LOG_LEVEL_CHOICES,
  105. hint="Log-Level fuer Konsolenausgabe",
  106. ),
  107. "logging.file_log_level": FieldMeta(
  108. editor=EditorType.SELECT,
  109. choices=_LOG_LEVEL_CHOICES,
  110. hint="Log-Level fuer Dateiausgabe",
  111. ),
  112. "logging.log_directory": FieldMeta(
  113. editor=EditorType.PATH,
  114. placeholder="logs",
  115. hint="Verzeichnis fuer Log-Dateien",
  116. ),
  117. "logging.max_file_size_mb": FieldMeta(
  118. editor=EditorType.NUMBER_INT,
  119. min_value=1,
  120. max_value=1000,
  121. hint="Maximale Log-Dateigroesse in MB",
  122. ),
  123. "logging.backup_count": FieldMeta(
  124. editor=EditorType.NUMBER_INT,
  125. min_value=0,
  126. max_value=100,
  127. hint="Anzahl der Log-Backup-Dateien",
  128. ),
  129. "logging.plugin_timeout_seconds": FieldMeta(
  130. editor=EditorType.NUMBER_FLOAT,
  131. min_value=1.0,
  132. max_value=300.0,
  133. hint="Plugin-Timeout in Sekunden",
  134. ),
  135. "logging.plugin_max_failures": FieldMeta(
  136. editor=EditorType.NUMBER_INT,
  137. min_value=1,
  138. max_value=100,
  139. hint="Maximale Plugin-Fehler vor Deaktivierung",
  140. ),
  141. # --- Security ---
  142. "security.encryption_enabled": FieldMeta(
  143. editor=EditorType.BOOL,
  144. requires_restart=True,
  145. hint="AES-256-GCM Verschluesselung aktivieren",
  146. ),
  147. "security.encryption_key_path": FieldMeta(
  148. editor=EditorType.PATH,
  149. placeholder="certs/encryption.key",
  150. requires_restart=True,
  151. ),
  152. "security.ssl_enabled": FieldMeta(
  153. editor=EditorType.BOOL,
  154. requires_restart=True,
  155. hint="SSL/TLS aktivieren",
  156. ),
  157. "security.ssl_cert_path": FieldMeta(
  158. editor=EditorType.PATH,
  159. placeholder="certs/server.crt",
  160. requires_restart=True,
  161. ),
  162. "security.ssl_key_path": FieldMeta(
  163. editor=EditorType.PATH,
  164. placeholder="certs/server.key",
  165. requires_restart=True,
  166. ),
  167. "security.allowed_mac_addresses": FieldMeta(
  168. editor=EditorType.LIST_TEXT,
  169. hint="Erlaubte MAC-Adressen (kommasepariert)",
  170. ),
  171. # --- Plugins ---
  172. "plugins.enabled": FieldMeta(
  173. editor=EditorType.BOOL,
  174. hint="Plugin-System aktivieren",
  175. ),
  176. "plugins.plugin_directory": FieldMeta(
  177. editor=EditorType.PATH,
  178. placeholder="plugins",
  179. ),
  180. "plugins.auto_reload": FieldMeta(
  181. editor=EditorType.BOOL,
  182. hint="Plugins automatisch neu laden bei Aenderungen",
  183. ),
  184. # --- Network ---
  185. "network.command_port": _port("Command-Port"),
  186. "network.audio_input_port": _port("Audio-Input-Port"),
  187. "network.audio_output_port": _port("Audio-Output-Port"),
  188. "network.music_port": _port("Musik-Port"),
  189. "network.config_port": _port("Config-Port"),
  190. "network.bind_address": FieldMeta(
  191. editor=EditorType.IP_ADDRESS,
  192. requires_restart=True,
  193. placeholder="0.0.0.0",
  194. hint="Bind-Adresse fuer den Server",
  195. ),
  196. "network.max_connections": FieldMeta(
  197. editor=EditorType.NUMBER_INT,
  198. min_value=1,
  199. max_value=1000,
  200. hint="Maximale gleichzeitige Verbindungen",
  201. ),
  202. # --- Audio ---
  203. "audio.sample_rate": FieldMeta(
  204. editor=EditorType.SELECT,
  205. choices=_SAMPLE_RATE_CHOICES,
  206. requires_restart=True,
  207. hint="Sprach-Audio Sample-Rate",
  208. ),
  209. "audio.channels": FieldMeta(
  210. editor=EditorType.SELECT,
  211. choices=_CHANNELS_CHOICES,
  212. requires_restart=True,
  213. ),
  214. "audio.bit_depth": FieldMeta(
  215. editor=EditorType.SELECT,
  216. choices=_BIT_DEPTH_CHOICES,
  217. requires_restart=True,
  218. ),
  219. "audio.music_sample_rate": FieldMeta(
  220. editor=EditorType.SELECT,
  221. choices=_SAMPLE_RATE_CHOICES,
  222. requires_restart=True,
  223. hint="Musik-Audio Sample-Rate",
  224. ),
  225. "audio.music_channels": FieldMeta(
  226. editor=EditorType.SELECT,
  227. choices=_CHANNELS_CHOICES,
  228. requires_restart=True,
  229. ),
  230. "audio.music_bit_depth": FieldMeta(
  231. editor=EditorType.SELECT,
  232. choices=_BIT_DEPTH_CHOICES,
  233. requires_restart=True,
  234. ),
  235. # --- Wakeword ---
  236. "wakeword.models": FieldMeta(
  237. editor=EditorType.LIST_SELECT,
  238. dynamic_source="wakeword_models",
  239. hint="Aktive Wakeword-Modelle",
  240. ),
  241. "wakeword.threshold": FieldMeta(
  242. editor=EditorType.NUMBER_FLOAT,
  243. min_value=0.0,
  244. max_value=1.0,
  245. step=0.05,
  246. hint="Erkennungsschwelle (0.0-1.0)",
  247. ),
  248. "wakeword.debounce_seconds": FieldMeta(
  249. editor=EditorType.NUMBER_FLOAT,
  250. min_value=0.0,
  251. max_value=10.0,
  252. hint="Entprellzeit in Sekunden",
  253. ),
  254. "wakeword.arbitration_timeout_seconds": FieldMeta(
  255. editor=EditorType.NUMBER_FLOAT,
  256. min_value=0.0,
  257. max_value=10.0,
  258. hint="Arbitrierungs-Timeout in Sekunden",
  259. ),
  260. "wakeword.min_audio_level": FieldMeta(
  261. editor=EditorType.NUMBER_FLOAT,
  262. min_value=0.0,
  263. max_value=1.0,
  264. ),
  265. "wakeword.min_confidence": FieldMeta(
  266. editor=EditorType.NUMBER_FLOAT,
  267. min_value=0.0,
  268. max_value=1.0,
  269. ),
  270. "wakeword.wakeword_trim_seconds": FieldMeta(
  271. editor=EditorType.NUMBER_FLOAT,
  272. min_value=0.0,
  273. max_value=5.0,
  274. ),
  275. # --- Voice Recognition ---
  276. "voice_recognition.enabled": FieldMeta(
  277. editor=EditorType.BOOL,
  278. ),
  279. "voice_recognition.model": FieldMeta(
  280. editor=EditorType.TEXT,
  281. placeholder="default",
  282. ),
  283. "voice_recognition.threshold": FieldMeta(
  284. editor=EditorType.NUMBER_FLOAT,
  285. min_value=0.0,
  286. max_value=1.0,
  287. ),
  288. # --- Conversation ---
  289. "conversation.max_silence_seconds": FieldMeta(
  290. editor=EditorType.NUMBER_FLOAT,
  291. min_value=0.5,
  292. max_value=30.0,
  293. ),
  294. "conversation.max_duration_seconds": FieldMeta(
  295. editor=EditorType.NUMBER_FLOAT,
  296. min_value=5.0,
  297. max_value=300.0,
  298. ),
  299. "conversation.timeout_seconds": FieldMeta(
  300. editor=EditorType.NUMBER_FLOAT,
  301. min_value=5.0,
  302. max_value=120.0,
  303. ),
  304. # --- Satellite Connection ---
  305. "satellite_connection.notification": FieldMeta(
  306. editor=EditorType.SELECT,
  307. choices=_NOTIFICATION_CHOICES,
  308. hint="Benachrichtigung bei Satellite-Verbindung",
  309. ),
  310. "satellite_connection.tts_text": FieldMeta(
  311. editor=EditorType.TEXT,
  312. placeholder="Verbunden",
  313. ),
  314. "satellite_connection.wave_file": FieldMeta(
  315. editor=EditorType.TEXT,
  316. placeholder="connected.wav",
  317. ),
  318. # --- STT Correction ---
  319. "stt_correction.enabled": FieldMeta(
  320. editor=EditorType.BOOL,
  321. hint="STT-Nachkorrektur aktivieren",
  322. ),
  323. "stt_correction.language": FieldMeta(
  324. editor=EditorType.TEXT,
  325. placeholder="de",
  326. ),
  327. "stt_correction.layers": FieldMeta(
  328. editor=EditorType.LIST_SELECT,
  329. choices=_STT_LAYER_CHOICES,
  330. hint="Aktive Korrektur-Layer",
  331. ),
  332. "stt_correction.protected_words": FieldMeta(
  333. editor=EditorType.LIST_TEXT,
  334. hint="Geschuetzte Woerter (kommasepariert)",
  335. ),
  336. "stt_correction.custom_aliases": FieldMeta(
  337. editor=EditorType.READONLY,
  338. hint="Benutzerdefinierte Aliase (nur Ansicht)",
  339. ),
  340. "stt_correction.symspell_max_edit_distance": FieldMeta(
  341. editor=EditorType.NUMBER_INT,
  342. min_value=1,
  343. max_value=5,
  344. ),
  345. "stt_correction.symspell_dictionary_path": FieldMeta(
  346. editor=EditorType.PATH,
  347. ),
  348. "stt_correction.kenlm_model_path": FieldMeta(
  349. editor=EditorType.PATH,
  350. ),
  351. "stt_correction.jamspell_model_path": FieldMeta(
  352. editor=EditorType.PATH,
  353. ),
  354. "stt_correction.hunspell_dict_path": FieldMeta(
  355. editor=EditorType.PATH,
  356. ),
  357. "stt_correction.languagetool_language": FieldMeta(
  358. editor=EditorType.TEXT,
  359. placeholder="de-DE",
  360. ),
  361. # --- Toplevel ---
  362. "satellites_directory": FieldMeta(editor=EditorType.PATH, placeholder="satellites"),
  363. "assets_directory": FieldMeta(editor=EditorType.PATH, placeholder="assets"),
  364. "models_directory": FieldMeta(editor=EditorType.PATH, placeholder="models"),
  365. "profile": FieldMeta(editor=EditorType.TEXT, placeholder="default"),
  366. }
  367. def build_standalone_registry() -> dict[str, FieldMeta]:
  368. """Baut die Feld-Registry fuer Standalone-Konfiguration."""
  369. registry: dict[str, FieldMeta] = {}
  370. # Logging (gleich wie Server)
  371. server_reg = build_server_registry()
  372. for key in list(server_reg):
  373. if key.startswith("logging."):
  374. registry[key] = server_reg[key]
  375. # Security (gleich wie Server)
  376. for key in list(server_reg):
  377. if key.startswith("security."):
  378. registry[key] = server_reg[key]
  379. # Plugins (gleich wie Server)
  380. for key in list(server_reg):
  381. if key.startswith("plugins."):
  382. registry[key] = server_reg[key]
  383. # Voice Recognition, Conversation, STT Correction (gleich wie Server)
  384. for key in list(server_reg):
  385. if key.startswith(("voice_recognition.", "conversation.", "stt_correction.")):
  386. registry[key] = server_reg[key]
  387. # Audio (Standalone hat andere Struktur)
  388. registry.update({
  389. "audio.sample_rate": FieldMeta(
  390. editor=EditorType.SELECT,
  391. choices=_SAMPLE_RATE_CHOICES,
  392. requires_restart=True,
  393. ),
  394. "audio.channels": FieldMeta(
  395. editor=EditorType.SELECT,
  396. choices=_CHANNELS_CHOICES,
  397. requires_restart=True,
  398. ),
  399. "audio.bit_depth": FieldMeta(
  400. editor=EditorType.SELECT,
  401. choices=_BIT_DEPTH_CHOICES,
  402. requires_restart=True,
  403. ),
  404. "audio.music_sample_rate": FieldMeta(
  405. editor=EditorType.SELECT,
  406. choices=_SAMPLE_RATE_CHOICES,
  407. requires_restart=True,
  408. ),
  409. "audio.music_channels": FieldMeta(
  410. editor=EditorType.SELECT,
  411. choices=_CHANNELS_CHOICES,
  412. requires_restart=True,
  413. ),
  414. "audio.music_bit_depth": FieldMeta(
  415. editor=EditorType.SELECT,
  416. choices=_BIT_DEPTH_CHOICES,
  417. requires_restart=True,
  418. ),
  419. "audio.buffer_size": FieldMeta(
  420. editor=EditorType.NUMBER_INT,
  421. min_value=64,
  422. max_value=8192,
  423. ),
  424. "audio.input_device": FieldMeta(editor=EditorType.TEXT, placeholder="Standard"),
  425. "audio.output_device": FieldMeta(editor=EditorType.TEXT, placeholder="Standard"),
  426. })
  427. # Wakeword (Client-Stil)
  428. registry.update({
  429. "wakeword.models": FieldMeta(
  430. editor=EditorType.LIST_SELECT,
  431. dynamic_source="wakeword_models",
  432. hint="Aktive Wakeword-Modelle",
  433. ),
  434. "wakeword.threshold": FieldMeta(
  435. editor=EditorType.NUMBER_FLOAT,
  436. min_value=0.0,
  437. max_value=1.0,
  438. step=0.05,
  439. ),
  440. "wakeword.model_directory": FieldMeta(
  441. editor=EditorType.PATH,
  442. placeholder="models/wakeword",
  443. ),
  444. "wakeword.use_onnx": FieldMeta(editor=EditorType.BOOL),
  445. "wakeword.enabled": FieldMeta(editor=EditorType.BOOL),
  446. "wakeword.silence_timeout_seconds": FieldMeta(
  447. editor=EditorType.NUMBER_FLOAT,
  448. min_value=0.5,
  449. max_value=30.0,
  450. ),
  451. "wakeword.max_recording_seconds": FieldMeta(
  452. editor=EditorType.NUMBER_FLOAT,
  453. min_value=5.0,
  454. max_value=300.0,
  455. ),
  456. "wakeword.no_speech_timeout_seconds": FieldMeta(
  457. editor=EditorType.NUMBER_FLOAT,
  458. min_value=1.0,
  459. max_value=30.0,
  460. ),
  461. "wakeword.pre_buffer_seconds": FieldMeta(
  462. editor=EditorType.NUMBER_FLOAT,
  463. min_value=0.0,
  464. max_value=5.0,
  465. ),
  466. "wakeword.wakeword_cooldown_seconds": FieldMeta(
  467. editor=EditorType.NUMBER_FLOAT,
  468. min_value=0.0,
  469. max_value=30.0,
  470. ),
  471. })
  472. # Sync
  473. registry.update({
  474. "sync.enabled": FieldMeta(editor=EditorType.BOOL),
  475. "sync.server_host": FieldMeta(
  476. editor=EditorType.IP_ADDRESS,
  477. placeholder="Server-IP",
  478. ),
  479. "sync.server_port": _port("Sync-Server-Port"),
  480. "sync.probe_interval_seconds": FieldMeta(
  481. editor=EditorType.NUMBER_FLOAT,
  482. min_value=5.0,
  483. max_value=600.0,
  484. ),
  485. "sync.sync_interval_seconds": FieldMeta(
  486. editor=EditorType.NUMBER_FLOAT,
  487. min_value=10.0,
  488. max_value=3600.0,
  489. ),
  490. "sync.connect_timeout_seconds": FieldMeta(
  491. editor=EditorType.NUMBER_FLOAT,
  492. min_value=1.0,
  493. max_value=60.0,
  494. ),
  495. "sync.sync_data_directory": FieldMeta(
  496. editor=EditorType.PATH,
  497. placeholder="./sync_data",
  498. ),
  499. })
  500. # Toplevel
  501. registry.update({
  502. "assets_directory": FieldMeta(editor=EditorType.PATH, placeholder="assets"),
  503. "models_directory": FieldMeta(editor=EditorType.PATH, placeholder="models"),
  504. "profile": FieldMeta(editor=EditorType.TEXT, placeholder="default"),
  505. "config_port": _port("Config-Port"),
  506. "room": FieldMeta(editor=EditorType.TEXT, placeholder="standalone"),
  507. "alias": FieldMeta(editor=EditorType.TEXT, placeholder="Trixy"),
  508. })
  509. return registry
  510. def build_client_registry() -> dict[str, FieldMeta]:
  511. """Baut die Feld-Registry fuer Client-Konfiguration."""
  512. registry: dict[str, FieldMeta] = {}
  513. # Server-Verbindung
  514. registry.update({
  515. "server.host": FieldMeta(
  516. editor=EditorType.IP_ADDRESS,
  517. placeholder="localhost",
  518. requires_restart=True,
  519. hint="Server-Adresse",
  520. ),
  521. "server.port": _port("Server-Port"),
  522. "server.reconnect_interval_seconds": FieldMeta(
  523. editor=EditorType.NUMBER_FLOAT,
  524. min_value=1.0,
  525. max_value=60.0,
  526. ),
  527. "server.connection_timeout_seconds": FieldMeta(
  528. editor=EditorType.NUMBER_FLOAT,
  529. min_value=1.0,
  530. max_value=60.0,
  531. ),
  532. })
  533. # Audio
  534. registry.update({
  535. "audio.sample_rate": FieldMeta(
  536. editor=EditorType.SELECT,
  537. choices=_SAMPLE_RATE_CHOICES,
  538. requires_restart=True,
  539. ),
  540. "audio.channels": FieldMeta(
  541. editor=EditorType.SELECT,
  542. choices=_CHANNELS_CHOICES,
  543. requires_restart=True,
  544. ),
  545. "audio.bit_depth": FieldMeta(
  546. editor=EditorType.SELECT,
  547. choices=_BIT_DEPTH_CHOICES,
  548. requires_restart=True,
  549. ),
  550. "audio.music_sample_rate": FieldMeta(
  551. editor=EditorType.SELECT,
  552. choices=_SAMPLE_RATE_CHOICES,
  553. requires_restart=True,
  554. ),
  555. "audio.music_channels": FieldMeta(
  556. editor=EditorType.SELECT,
  557. choices=_CHANNELS_CHOICES,
  558. requires_restart=True,
  559. ),
  560. "audio.music_bit_depth": FieldMeta(
  561. editor=EditorType.SELECT,
  562. choices=_BIT_DEPTH_CHOICES,
  563. requires_restart=True,
  564. ),
  565. "audio.buffer_size": FieldMeta(
  566. editor=EditorType.NUMBER_INT,
  567. min_value=64,
  568. max_value=8192,
  569. ),
  570. "audio.input_device": FieldMeta(editor=EditorType.TEXT, placeholder="Standard"),
  571. "audio.output_device": FieldMeta(editor=EditorType.TEXT, placeholder="Standard"),
  572. })
  573. # Wakeword
  574. registry.update({
  575. "wakeword.models": FieldMeta(
  576. editor=EditorType.LIST_SELECT,
  577. dynamic_source="wakeword_models",
  578. hint="Aktive Wakeword-Modelle",
  579. ),
  580. "wakeword.threshold": FieldMeta(
  581. editor=EditorType.NUMBER_FLOAT,
  582. min_value=0.0,
  583. max_value=1.0,
  584. step=0.05,
  585. ),
  586. "wakeword.model_directory": FieldMeta(
  587. editor=EditorType.PATH,
  588. placeholder="models/wakeword",
  589. ),
  590. "wakeword.use_onnx": FieldMeta(editor=EditorType.BOOL),
  591. "wakeword.enabled": FieldMeta(editor=EditorType.BOOL),
  592. "wakeword.silence_timeout_seconds": FieldMeta(
  593. editor=EditorType.NUMBER_FLOAT,
  594. min_value=0.5,
  595. max_value=30.0,
  596. ),
  597. "wakeword.max_recording_seconds": FieldMeta(
  598. editor=EditorType.NUMBER_FLOAT,
  599. min_value=5.0,
  600. max_value=300.0,
  601. ),
  602. "wakeword.no_speech_timeout_seconds": FieldMeta(
  603. editor=EditorType.NUMBER_FLOAT,
  604. min_value=1.0,
  605. max_value=30.0,
  606. ),
  607. "wakeword.pre_buffer_seconds": FieldMeta(
  608. editor=EditorType.NUMBER_FLOAT,
  609. min_value=0.0,
  610. max_value=5.0,
  611. ),
  612. "wakeword.wakeword_cooldown_seconds": FieldMeta(
  613. editor=EditorType.NUMBER_FLOAT,
  614. min_value=0.0,
  615. max_value=30.0,
  616. ),
  617. })
  618. # Identity
  619. registry.update({
  620. "identity.room": FieldMeta(editor=EditorType.TEXT, placeholder="Raum-Name"),
  621. "identity.alias": FieldMeta(editor=EditorType.TEXT, placeholder="Alias"),
  622. "identity.mac_address": FieldMeta(
  623. editor=EditorType.READONLY,
  624. hint="Automatisch ermittelt",
  625. ),
  626. })
  627. # Logging
  628. registry.update({
  629. "logging.level": FieldMeta(
  630. editor=EditorType.SELECT,
  631. choices=_LOG_LEVEL_CHOICES,
  632. ),
  633. "logging.log_directory": FieldMeta(
  634. editor=EditorType.PATH,
  635. placeholder="logs",
  636. ),
  637. })
  638. # Toplevel
  639. registry.update({
  640. "config_port": _port("Config-Port"),
  641. "assets_directory": FieldMeta(editor=EditorType.PATH, placeholder="assets"),
  642. "profile": FieldMeta(editor=EditorType.TEXT, placeholder="default"),
  643. })
  644. return registry
  645. def get_field_registry(instance_type: str) -> dict[str, FieldMeta]:
  646. """
  647. Factory: Gibt die passende Feld-Registry fuer den Instanz-Typ zurueck.
  648. Args:
  649. instance_type: "server", "standalone" oder "client"
  650. Returns:
  651. Dictionary mit Pfad -> FieldMeta Zuordnung
  652. """
  653. builders = {
  654. "server": build_server_registry,
  655. "standalone": build_standalone_registry,
  656. "client": build_client_registry,
  657. }
  658. builder = builders.get(instance_type)
  659. if builder:
  660. return builder()
  661. return {}
  662. def infer_field_meta(value: object) -> FieldMeta:
  663. """
  664. Inferiert FieldMeta aus dem Python-Typ des aktuellen Werts.
  665. Wird als Fallback verwendet wenn ein Feld nicht in der
  666. Registry eingetragen ist.
  667. Args:
  668. value: Aktueller Wert des Feldes
  669. Returns:
  670. Passendes FieldMeta basierend auf dem Typ
  671. """
  672. if isinstance(value, bool):
  673. return FieldMeta(editor=EditorType.BOOL)
  674. if isinstance(value, int):
  675. return FieldMeta(editor=EditorType.NUMBER_INT)
  676. if isinstance(value, float):
  677. return FieldMeta(editor=EditorType.NUMBER_FLOAT)
  678. if isinstance(value, list):
  679. return FieldMeta(editor=EditorType.LIST_TEXT)
  680. if isinstance(value, dict):
  681. return FieldMeta(editor=EditorType.READONLY)
  682. return FieldMeta(editor=EditorType.TEXT)