Merge pull request #779 from pipecat-ai/aleix/websocket-server-audio-mixins-fix

frames: fix AudioRawFrame mixin
This commit is contained in:
Aleix Conchillo Flaqué
2024-12-04 19:08:41 -08:00
committed by GitHub
2 changed files with 7 additions and 3 deletions

View File

@@ -79,7 +79,10 @@ class AudioRawFrame:
audio: bytes
sample_rate: int
num_channels: int
num_frames: int = field(init=False)
num_frames: int = field(default=0, init=False)
def __post_init__(self):
self.num_frames = int(len(self.audio) / (self.num_channels * 2))
@dataclass

View File

@@ -34,10 +34,11 @@ class ProtobufFrameSerializer(FrameSerializer):
# ignoring linter errors; we check that type(frame) is in this dict above
proto_optional_name = self.SERIALIZABLE_TYPES[type(frame)] # type: ignore
proto_attr = getattr(proto_frame, proto_optional_name)
for field in dataclasses.fields(frame): # type: ignore
value = getattr(frame, field.name)
if value:
setattr(getattr(proto_frame, proto_optional_name), field.name, value)
if value and hasattr(proto_attr, field.name):
setattr(proto_attr, field.name, value)
result = proto_frame.SerializeToString()
return result