From 13c27eaa1ddb91f7615b5747f064b2654a0b4175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Wed, 4 Dec 2024 13:25:37 -0800 Subject: [PATCH] frames: fix AudioRawFrame mixin --- src/pipecat/frames/frames.py | 5 ++++- src/pipecat/serializers/protobuf.py | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pipecat/frames/frames.py b/src/pipecat/frames/frames.py index 17059700a..7b2dc8aaa 100644 --- a/src/pipecat/frames/frames.py +++ b/src/pipecat/frames/frames.py @@ -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 diff --git a/src/pipecat/serializers/protobuf.py b/src/pipecat/serializers/protobuf.py index 2adf403a5..654e87b24 100644 --- a/src/pipecat/serializers/protobuf.py +++ b/src/pipecat/serializers/protobuf.py @@ -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