Sync voice chatId session handling

This commit is contained in:
Xin Wang
2026-06-01 10:08:15 +08:00
parent 6df6c16e1d
commit 00c1bbdc6b
8 changed files with 228 additions and 32 deletions

View File

@@ -18,7 +18,6 @@ from pipecat.frames.frames import (
OutputAudioRawFrame,
OutputTransportMessageFrame,
OutputTransportMessageUrgentFrame,
TextFrame,
TranscriptionFrame,
UserImageRawFrame,
)
@@ -64,13 +63,15 @@ class ProductWebsocketSerializer(FrameSerializer):
timestamp=frame.timestamp,
)
if isinstance(frame, TextFrame):
return self._event("response.text.delta", text=frame.text)
# ProductTextStreamProcessor owns response.text.* events. TTS can also
# emit TextFrame subclasses internally, so serializing them here would
# make clients render duplicate assistant text.
if isinstance(frame, (OutputTransportMessageFrame, OutputTransportMessageUrgentFrame)):
if self.should_ignore_frame(frame):
return None
message = frame.message
# Allow callers to emit a named protocol event by pushing a
# transport-message frame whose payload already carries a `type`.
if isinstance(message, dict) and isinstance(message.get("type"), str):
event_type = message["type"]
payload = {k: v for k, v in message.items() if k != "type"}
@@ -99,10 +100,12 @@ class ProductWebsocketSerializer(FrameSerializer):
message_type = message.get("type")
if message_type == "session.start":
chat_id = message.get("chatId") or message.get("chat_id")
return InputTransportMessageFrame(
message={
"type": "session.started",
"protocol": self.protocol,
"chatId": chat_id if isinstance(chat_id, str) else None,
"audio": {
"encoding": "pcm_s16le",
"sample_rate": self._sample_rate,