o
    i	                     @  sb   d dl mZ d dlmZmZ d dlmZ ddlmZm	Z	 edddZ
edddZ
dddZ
dS )    )annotations)AsyncGeneratorAsyncIterable)overload   )_basic_word	tokenizertextstrreplacementsdict[str, str]returnc                 C     d S N r	   r   r   r   _/var/www/html/livekit_bhavya/venv/lib/python3.10/site-packages/livekit/agents/tokenize/utils.pyreplace_words	      r   AsyncIterable[str]c                 C  r   r   r   r   r   r   r   r      r   str | AsyncIterable[str]c                   s`   dd   D dfd	d
 ttr%tjdd} |\}S d fdd}| S )z
    Replace words in the given (async) text. The replacements are case-insensitive and the
    replacement will keep the case of the original word.
    Args:
        text: text to replace words in
        words: dictionary of words to replace
    c                 S  s   i | ]	\}}|  |qS r   )lower).0kvr   r   r   
<dictcomp>&   s    z!replace_words.<locals>.<dictcomp>r	   r
   wordslist[tuple[str, int, int]]r   tuple[str, int]c           
        s   d}d}|D ]C\}}}| dtj}t|t| } | }	|	rE| d ||  |	 | || | d   } |t|	t| | 7 }|| }q| |fS )Nr    )rstripjoinr   PUNCTUATIONSlengetr   )
r	   r   offsetprocessed_indexwordstart_index	end_indexno_punctuationpunctuation_offreplacement)r   r   r   _process_words(   s    
z%replace_words.<locals>._process_wordsFignore_punctuationAsyncGenerator[str, None]c                   s   d} 2 z03 d H W }| |7 } t j| dd}t|dkrq | |d d \} }| d | V  | |d  } q6 | rLt j| dd} | |\} }| V  d S d S )Nr   Fr.   r   )r   split_wordsr#   )bufferchunkr   procesed_index_)r-   r	   r   r   _replace_wordsA   s    
z%replace_words.<locals>._replace_wordsN)r	   r
   r   r   r   r   )r   r0   )items
isinstancer
   r   r2   )r	   r   r   r6   r7   r   )r-   r   r	   r   r      s   
N)r	   r
   r   r   r   r
   )r	   r   r   r   r   r   )r	   r   r   r   r   r   )
__future__r   collections.abcr   r   typingr   r   r   r   r   r   r   r   r   <module>   s    