audio.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. """
  2. Audio Streaming Command Classes
  3. This module implements commands for audio streaming in the Trixy system.
  4. """
  5. from typing import Optional, Dict, Any
  6. from dataclasses import dataclass, field
  7. from .base import TrixyCommand, CommandResponse, ValidationError
  8. @dataclass
  9. class AudioStreamStartCommand(TrixyCommand):
  10. """Command to start audio streaming."""
  11. stream_type: str = field(default="input") # input, output, music
  12. satellite_id: str = field(default="")
  13. audio_format: Dict[str, Any] = field(default_factory=dict)
  14. def validate(self) -> bool:
  15. if self.stream_type not in ["input", "output", "music"]:
  16. raise ValidationError("Invalid stream_type")
  17. return True
  18. def get_command_name(self) -> str:
  19. return "AudioStreamStartCommand"
  20. @dataclass
  21. class AudioStreamStopCommand(TrixyCommand):
  22. """Command to stop audio streaming."""
  23. stream_type: str = field(default="input")
  24. satellite_id: str = field(default="")
  25. def validate(self) -> bool:
  26. return True
  27. def get_command_name(self) -> str:
  28. return "AudioStreamStopCommand"
  29. @dataclass
  30. class AudioDataCommand(TrixyCommand):
  31. """Command containing audio data."""
  32. audio_data: bytes = field(default=b"")
  33. format_info: Dict[str, Any] = field(default_factory=dict)
  34. def validate(self) -> bool:
  35. return True
  36. def get_command_name(self) -> str:
  37. return "AudioDataCommand"
  38. @dataclass
  39. class AudioConfigCommand(TrixyCommand):
  40. """Command to configure audio settings."""
  41. config_changes: Dict[str, Any] = field(default_factory=dict)
  42. def validate(self) -> bool:
  43. return True
  44. def get_command_name(self) -> str:
  45. return "AudioConfigCommand"
  46. @dataclass
  47. class AudioStreamStartResponse(CommandResponse):
  48. """Response to audio stream start command."""
  49. stream_started: bool = field(default=False)
  50. def validate(self) -> bool:
  51. return True
  52. def get_response_name(self) -> str:
  53. return "AudioStreamStartResponse"
  54. @dataclass
  55. class AudioStreamStopResponse(CommandResponse):
  56. """Response to audio stream stop command."""
  57. stream_stopped: bool = field(default=False)
  58. def validate(self) -> bool:
  59. return True
  60. def get_response_name(self) -> str:
  61. return "AudioStreamStopResponse"
  62. @dataclass
  63. class AudioConfigResponse(CommandResponse):
  64. """Response to audio config command."""
  65. config_applied: bool = field(default=False)
  66. def validate(self) -> bool:
  67. return True
  68. def get_response_name(self) -> str:
  69. return "AudioConfigResponse"
  70. __all__ = [
  71. "AudioStreamStartCommand", "AudioStreamStopCommand", "AudioDataCommand", "AudioConfigCommand",
  72. "AudioStreamStartResponse", "AudioStreamStopResponse", "AudioConfigResponse"
  73. ]