diff --git a/CHANGELOG.md b/CHANGELOG.md index 086b05861..fae0d17ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added `user_id` field to `TranscriptionMessage`. This allows identifying the + user in a multi-user scenario. Note that this requires that + `TranscriptionFrame` has the `user_id` properly set. + - Added new `PipelineTask` event handlers `on_pipeline_started`, `on_pipeline_stopped`, `on_pipeline_ended` and `on_pipeline_cancelled`, which correspond to the `StartFrame`, `StopFrame`, `EndFrame` and `CancelFrame` diff --git a/src/pipecat/frames/frames.py b/src/pipecat/frames/frames.py index 2db21495b..18bc2874b 100644 --- a/src/pipecat/frames/frames.py +++ b/src/pipecat/frames/frames.py @@ -288,6 +288,7 @@ class TranscriptionMessage: role: Literal["user", "assistant"] content: str + user_id: Optional[str] = None timestamp: Optional[str] = None diff --git a/src/pipecat/processors/transcript_processor.py b/src/pipecat/processors/transcript_processor.py index 85bcd072d..97ccd0cd4 100644 --- a/src/pipecat/processors/transcript_processor.py +++ b/src/pipecat/processors/transcript_processor.py @@ -62,7 +62,7 @@ class UserTranscriptProcessor(BaseTranscriptProcessor): if isinstance(frame, TranscriptionFrame): message = TranscriptionMessage( - role="user", content=frame.text, timestamp=frame.timestamp + role="user", user_id=frame.user_id, content=frame.text, timestamp=frame.timestamp ) await self._emit_update([message]) diff --git a/tests/test_transcript_processor.py b/tests/test_transcript_processor.py index 601631a8e..db663e086 100644 --- a/tests/test_transcript_processor.py +++ b/tests/test_transcript_processor.py @@ -64,6 +64,7 @@ class TestUserTranscriptProcessor(unittest.IsolatedAsyncioTestCase): message = update_frame.messages[0] self.assertEqual(message.role, "user") self.assertEqual(message.content, "Hello, world!") + self.assertEqual(message.user_id, "test_user") self.assertEqual(message.timestamp, timestamp) async def test_event_handler(self):