server.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. ])
  97. custom_aliases: dict[str, str] = field(default_factory=lambda: {
  98. "shop": "stopp",
  99. "schop": "stopp",
  100. })
  101. symspell_max_edit_distance: int = 2
  102. symspell_dictionary_path: str = ""
  103. kenlm_model_path: str = "models/kenlm/de.binary"
  104. jamspell_model_path: str = "models/jamspell/de.bin"
  105. hunspell_dict_path: str = "/usr/share/hunspell/de_DE"
  106. languagetool_language: str = "de-DE"
  107. @dataclass
  108. class EmailPGPConfig:
  109. """PGP-Konfiguration fuer den Email-Service."""
  110. enabled: bool = False
  111. gpg_home: str = "~/.gnupg"
  112. sign_key: str = ""
  113. passphrase: str = ""
  114. always_sign: bool = False
  115. always_encrypt: bool = False
  116. recipient_keys: dict[str, str] = field(default_factory=dict)
  117. @dataclass
  118. class EmailServiceConfig:
  119. """E-Mail-Service Konfiguration (SMTP-Versand + optionales PGP)."""
  120. smtp_host: str = ""
  121. smtp_port: int = 587
  122. smtp_user: str = ""
  123. smtp_password: str = ""
  124. smtp_ssl: bool = True
  125. smtp_starttls: bool = True
  126. from_address: str = ""
  127. from_name: str = "Trixy"
  128. reply_to: str = ""
  129. organization: str = ""
  130. pgp: EmailPGPConfig = field(default_factory=EmailPGPConfig)
  131. @dataclass
  132. class ServerConfig:
  133. """Haupt-Server-Konfiguration."""
  134. network: NetworkConfig = field(default_factory=NetworkConfig)
  135. security: SecurityConfig = field(default_factory=SecurityConfig)
  136. audio: AudioConfig = field(default_factory=AudioConfig)
  137. wakeword: WakewordConfig = field(default_factory=WakewordConfig)
  138. voice_recognition: VoiceRecognitionConfig = field(default_factory=VoiceRecognitionConfig)
  139. conversation: ConversationConfig = field(default_factory=ConversationConfig)
  140. plugins: PluginConfig = field(default_factory=PluginConfig)
  141. logging: LoggingConfig = field(default_factory=LoggingConfig)
  142. satellite_connection: SatelliteConnectionConfig = field(default_factory=SatelliteConnectionConfig)
  143. stt_correction: STTCorrectionConfig = field(default_factory=STTCorrectionConfig)
  144. email: EmailServiceConfig = field(default_factory=EmailServiceConfig)
  145. satellites_directory: str = "satellites"
  146. assets_directory: str = "assets"
  147. models_directory: str = "models"
  148. profile: str = "default"