server.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. # -*- coding: utf-8 -*-
  2. """
  3. Server-Konfiguration.
  4. """
  5. from dataclasses import dataclass, field
  6. from enum import IntFlag
  7. class ConnectionNotification(IntFlag):
  8. """Benachrichtigungsoptionen bei Client-Verbindung."""
  9. NONE = 0
  10. AUDIO_TTS = 1 << 0 # TTS sagt "Connected"
  11. AUDIO_WAVE = 1 << 1 # Wave-Datei "connected.wav" abspielen
  12. @dataclass
  13. class SatelliteConnectionConfig:
  14. """Konfiguration für Satellite-Verbindungsbenachrichtigungen."""
  15. notification: int = 0 # ConnectionNotification Flags
  16. tts_text: str = "Verbunden"
  17. wave_file: str = "connected.wav"
  18. mic_test_tts_text: str = "Teste Mikrofon. Audio wird weitergeleitet"
  19. @dataclass
  20. class NetworkConfig:
  21. """Netzwerk-Konfiguration für den Server."""
  22. command_port: int = 2101
  23. audio_input_port: int = 2102
  24. audio_output_port: int = 2103
  25. music_port: int = 2104
  26. config_port: int = 2105
  27. bind_address: str = "0.0.0.0"
  28. max_connections: int = 100
  29. @dataclass
  30. class SecurityConfig:
  31. """Sicherheits-Konfiguration."""
  32. encryption_enabled: bool = True
  33. encryption_key_path: str = "certs/encryption.key"
  34. ssl_enabled: bool = False
  35. ssl_cert_path: str = "certs/server.crt"
  36. ssl_key_path: str = "certs/server.key"
  37. allowed_mac_addresses: list[str] = field(default_factory=list)
  38. @dataclass
  39. class AudioConfig:
  40. """Audio-Konfiguration."""
  41. # Sprach-Audio (Wakeword, STT)
  42. sample_rate: int = 16000
  43. channels: int = 1
  44. bit_depth: int = 16
  45. # Musik-Streaming (konfigurierbar für Audio-Device-Kompatibilität)
  46. music_sample_rate: int = 44100 # 44.1kHz - Standard für die meisten Geräte
  47. music_channels: int = 2
  48. music_bit_depth: int = 16
  49. @dataclass
  50. class WakewordConfig:
  51. """Wakeword-Erkennungs-Konfiguration."""
  52. models: list[str] = field(default_factory=lambda: ["custom", "system_command"])
  53. admin_wakewords: list[str] = field(default_factory=lambda: ["system_command"])
  54. threshold: float = 0.5
  55. debounce_seconds: float = 1.0
  56. arbitration_timeout_seconds: float = 1.0
  57. min_audio_level: float = 0.0
  58. min_confidence: float = 0.3
  59. wakeword_trim_seconds: float = 1.0 # Sekunden am Anfang trimmen (Pre-Buffer + Wakeword-Tail)
  60. @dataclass
  61. class VoiceRecognitionConfig:
  62. """Sprechererkennungs-Konfiguration."""
  63. model: str = "default"
  64. enabled: bool = True
  65. threshold: float = 0.7
  66. @dataclass
  67. class ConversationConfig:
  68. """Konversations-Konfiguration."""
  69. max_silence_seconds: float = 3.0
  70. max_duration_seconds: float = 60.0
  71. timeout_seconds: float = 30.0
  72. @dataclass
  73. class PluginConfig:
  74. """Plugin-Konfiguration."""
  75. enabled: bool = True
  76. plugin_directory: str = "plugins"
  77. auto_reload: bool = False
  78. @dataclass
  79. class LoggingConfig:
  80. """Logging-Konfiguration."""
  81. level: str = "INFO"
  82. file_log_level: str = "INFO"
  83. log_directory: str = "logs"
  84. max_file_size_mb: int = 10
  85. backup_count: int = 5
  86. plugin_timeout_seconds: float = 30.0
  87. plugin_max_failures: int = 3
  88. @dataclass
  89. class STTCorrectionConfig:
  90. """Konfiguration fuer die STT-Nachkorrektur."""
  91. enabled: bool = True
  92. language: str = "de"
  93. layers: list[str] = field(default_factory=lambda: ["symspell", "phonetic", "kenlm"])
  94. protected_words: list[str] = field(default_factory=lambda: [
  95. "Eminem", "Rammstein", "AC/DC", "Trixy", "Alexa",
  96. "Conan", "Naruto", "Crunchyroll", "Netflix",
  97. ])
  98. custom_aliases: dict[str, str] = field(default_factory=lambda: {
  99. "shop": "stopp",
  100. "schop": "stopp",
  101. })
  102. symspell_max_edit_distance: int = 2
  103. symspell_dictionary_path: str = ""
  104. kenlm_model_path: str = "models/kenlm/de.binary"
  105. jamspell_model_path: str = "models/jamspell/de.bin"
  106. hunspell_dict_path: str = "/usr/share/hunspell/de_DE"
  107. languagetool_language: str = "de-DE"
  108. @dataclass
  109. class EmailPGPConfig:
  110. """PGP-Konfiguration fuer den Email-Service."""
  111. enabled: bool = False
  112. gpg_home: str = "~/.gnupg"
  113. sign_key: str = ""
  114. passphrase: str = ""
  115. always_sign: bool = False
  116. always_encrypt: bool = False
  117. recipient_keys: dict[str, str] = field(default_factory=dict)
  118. @dataclass
  119. class EmailServiceConfig:
  120. """E-Mail-Service Konfiguration (SMTP-Versand + optionales PGP)."""
  121. smtp_host: str = ""
  122. smtp_port: int = 587
  123. smtp_user: str = ""
  124. smtp_password: str = ""
  125. smtp_ssl: bool = True
  126. smtp_starttls: bool = True
  127. from_address: str = ""
  128. from_name: str = "Trixy"
  129. reply_to: str = ""
  130. organization: str = ""
  131. pgp: EmailPGPConfig = field(default_factory=EmailPGPConfig)
  132. @dataclass
  133. class ServerConfig:
  134. """Haupt-Server-Konfiguration."""
  135. network: NetworkConfig = field(default_factory=NetworkConfig)
  136. security: SecurityConfig = field(default_factory=SecurityConfig)
  137. audio: AudioConfig = field(default_factory=AudioConfig)
  138. wakeword: WakewordConfig = field(default_factory=WakewordConfig)
  139. voice_recognition: VoiceRecognitionConfig = field(default_factory=VoiceRecognitionConfig)
  140. conversation: ConversationConfig = field(default_factory=ConversationConfig)
  141. plugins: PluginConfig = field(default_factory=PluginConfig)
  142. logging: LoggingConfig = field(default_factory=LoggingConfig)
  143. satellite_connection: SatelliteConnectionConfig = field(default_factory=SatelliteConnectionConfig)
  144. stt_correction: STTCorrectionConfig = field(default_factory=STTCorrectionConfig)
  145. email: EmailServiceConfig = field(default_factory=EmailServiceConfig)
  146. satellites_directory: str = "satellites"
  147. assets_directory: str = "assets"
  148. models_directory: str = "models"
  149. profile: str = "default"