diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f480b577..8bc723299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed an issue in the `TranscriptProcessor` where newline characters could + cause the transcript output to be corrupted (e.g. missing all spaces). + - Fixed an issue in `AudioBufferProcessor` when using `SmallWebRTCTransport` where, if the microphone was muted, track timing was not respected. diff --git a/src/pipecat/processors/transcript_processor.py b/src/pipecat/processors/transcript_processor.py index df6dd469b..424374faf 100644 --- a/src/pipecat/processors/transcript_processor.py +++ b/src/pipecat/processors/transcript_processor.py @@ -140,11 +140,13 @@ class AssistantTranscriptProcessor(BaseTranscriptProcessor): Result: "Hello there how are you" """ if self._current_text_parts and self._aggregation_start_time: + # Check specifically for space characters, previously isspace() was used + # but that includes all whitespace characters (e.g. \n), not just spaces. has_leading_spaces = any( - part and part[0].isspace() for part in self._current_text_parts[1:] + part and part[0] == " " for part in self._current_text_parts[1:] ) has_trailing_spaces = any( - part and part[-1].isspace() for part in self._current_text_parts[:-1] + part and part[-1] == " " for part in self._current_text_parts[:-1] ) # If there are embedded spaces in the fragments, use direct concatenation