
    qi                     R    d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
  G d de      Zy)zText sentence aggregation processor for Pipecat.

This module provides a frame processor that accumulates text frames into
complete sentences, only outputting when a sentence-ending pattern is detected.
    )EndFrameFrameInterimTranscriptionFrame	TextFrame)FrameDirectionFrameProcessor)match_endofsentencec                   6     e Zd ZdZ fdZdedef fdZ xZS )SentenceAggregatora  Aggregates text frames into complete sentences.

    This processor accumulates incoming text frames until a sentence-ending
    pattern is detected, then outputs the complete sentence as a single frame.
    Useful for ensuring downstream processors receive coherent, complete sentences
    rather than fragmented text.

    Frame input/output::

        TextFrame("Hello,") -> None
        TextFrame(" world.") -> TextFrame("Hello, world.")
    c                 0    t         |           d| _        y)zInitialize the sentence aggregator.

        Sets up internal state for accumulating text frames into complete sentences.
         N)super__init___aggregation)self	__class__s    Y/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/processors/aggregators/sentence.pyr   zSentenceAggregator.__init__    s    
 	    frame	directionc                 `  K   t         |   ||       d{    t        |t              ryt        |t              ri| xj
                  |j                  z  c_        t        | j
                        r4| j                  t	        | j
                               d{    d| _        yyt        |t              rR| j
                  r,| j                  t	        | j
                               d{    | j                  |       d{    y| j                  ||       d{    y7 7 7 >7 '7 w)zProcess incoming frames and aggregate text into complete sentences.

        Args:
            frame: The incoming frame to process.
            direction: The direction of frame flow in the pipeline.
        Nr   )
r   process_frame
isinstancer   r   r   textr	   
push_framer   )r   r   r   r   s      r   r   z SentenceAggregator.process_frame(   s      g#E9555 e67eY'+"4#4#45ooi0A0A&BCCC$&! 6 x(  ooi0A0A&BCCC//%(((//%333! 	6 D D(3sY   D.D#B D.D&AD.)D(*D.D*D.D,D.&D.(D.*D.,D.)	__name__
__module____qualname____doc__r   r   r   r   __classcell__)r   s   @r   r   r      s%    4 4> 4 4r   r   N)r   pipecat.frames.framesr   r   r   r   "pipecat.processors.frame_processorr   r   pipecat.utils.stringr	   r    r   r   <module>r%      s%    X W M 4-4 -4r   