
    ^j$                         d dl mZ ddlmZmZ ddlmZmZmZ ddl	m
Z
mZ ddlmZmZ  ej                  e      Z G d ded	
      Ze G d de             ZdgZy)    )DecodeStream   )
AudioInputmake_list_of_audio)ProcessingKwargsProcessorMixinUnpack)PreTokenizedInput	TextInput)auto_docstringloggingc                   .    e Zd Zdddddddddd	d
idZy)ParakeetProcessorKwargsi>  longestT   )sampling_ratepaddingreturn_attention_masksubsampling_factorrightF)r   padding_sideadd_special_tokensreturn_tensorspt)audio_kwargstext_kwargscommon_kwargsN)__name__
__module____qualname__	_defaults     {/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/parakeet/processing_parakeet.pyr   r      s6     # %)"#	
 #"'

 +D1Ir#   r   F)totalc                        e Zd Zd fd	Zed        Ze	 	 ddedee	z  e
e   z  e
e	   z  dz  dedz  dee   fd       Zed	        Zd
 ZdddZg dfdZ xZS )ParakeetProcessorNc                 n    || _         |j                  |      | _        || _        t        |   ||       y)a  
        blank_token (`str`, *optional*, defaults to `"<blank>"`):
            Blank token for transducer decoding.
        decoder_type (`str`, *optional*):
            Decoding/timestamp emission mode. Possible values:

            - `"ctc"`: Consecutive identical tokens are merged into one emission.
            - `"rnnt"`: Repeated tokens are kept; each token gets a 1-frame timestamp span.
            - `"tdt"`: Repeated tokens are kept; each token span is based on its predicted duration. Punctuation is attached to the preceding token.

            If `None` (older checkpoints) the decoder type is inferred automatically for backward compatibility.
        N)blank_tokenconvert_tokens_to_idsblank_token_iddecoder_typesuper__init__)selffeature_extractor	tokenizerr)   r,   	__class__s        r$   r.   zParakeetProcessor.__init__.   s8     ''==kJ(*I6r#   c                     | j                   | j                   S | j                  | j                  j                         vrdS dS )Nctctdt)r,   r)   r1   	get_vocab)r/   s    r$   _decoder_typezParakeetProcessor._decoder_type@   sB    ($$$ ((0H0H0JJuUPUUr#   audiotextr   kwargsc                    t        |      } | j                  t        fd| j                  j                  i|}| t
        j                  d|d   d    d       n#||d   d   k7  rt        d| d|d   d    d      | | j                  |fi |d   }| | j                  |fi |d	   }|S d
   d<   t        |t              r|g}|D cg c]  }| j                  |z    }	} | j                  |	fi |d	   }
|
d
   |d<   |S c c}w )a  
        sampling_rate (`int`, *optional*):
            The sampling rate of the input audio in Hz. This should match the sampling rate expected by the feature
            extractor (defaults to 16000 Hz). If provided, it will be validated against the processor's expected
            sampling rate, and an error will be raised if they don't match. If not provided, a warning will be
            issued and the default sampling rate will be assumed.
        tokenizer_init_kwargszUYou've provided audio without specifying the sampling rate. It will be assumed to be r   r   z$, which can result in silent errors.z The sampling rate of the audio (z5) does not match the sampling rate of the processor (zD). Please provide resampled the audio to the expected sampling rate.r   	input_idslabelsdecoder_input_ids)r   _merge_kwargsr   r1   init_kwargsloggerwarning_once
ValueErrorr0   
isinstancestrr)   )r/   r8   r9   r   r:   output_kwargsinputs	encodingstdecoder_textdecoder_encodingss              r$   __call__zParakeetProcessor.__call__I   s    #5)***#
"&.."<"<
 
  ghu  wE  iF  GV  iW  hX  X|  } mN;OLL2=/Av  xE  FT  xU  Ve  xf  wg  gk  l  +T++ES]>5RSF&tL}]/KLI<M(5F8 $$v:>?QD,,q0?L? .| \}]?[ \*;K*HF&'M @s   D	c                 <    | j                   j                  }|ddgz   S )Nr>   r?   )r0   model_input_names)r/   feature_extractor_input_namess     r$   rO   z#ParakeetProcessor.model_input_names{   s%    (,(>(>(P(P%,:M/NNNr#   c                 x    |j                  d| j                  dk(          | j                  j                  |i |S )Ngroup_tokensr4   )
setdefaultr7   r1   batch_decode)r/   argsr:   s      r$   rT   zParakeetProcessor.batch_decode   s9    .$*<*<*EF*t~~**D;F;;r#   )	durationsc                   |j                  d| j                  dk(          | j                  j                  |i |}||d   }|j	                  d      |z
  }| j                  t        | j                  j                        }| j                  j                  | j                  j                  z  |d   d   z  }| j                  j                  | j                  h}	g }
t        |||      D ]  \  }}}t        d	
      }g }t        |      D ]  \  }}t!        |      |	v r|j#                  | j                  j$                  t!        |            }|F| j                  dk(  rt!        ||         nd}t!        ||         }|j'                  ||||z   d        |
j'                  | j)                  ||              ||
fS |S )z
        Forward arguments to [`~PreTrainedTokenizer.decode`] and post-process the timestamps (if provided for TDT) as
        in the NeMo library.
        rR   r4   r   )dim)r<   r   r   T)skip_special_tokensr5      )tokenstartend)rS   r7   r1   decodecumsumr@   r   rA   r0   
hop_lengthr   pad_token_idr+   zipr   	enumerateintstep
_tokenizerappend_refine_timestamps)r/   rV   rU   r:   decoded	token_ids
timestampsrG   
frame_rateskip_idsproc_timestamps	batch_idsbatch_timestampsbatch_durationsstreamtimestamp_dictitoken_idchunk
token_spanr]   s                        r$   r_   zParakeetProcessor.decode   s   
 	.$*<*<*EF'$..''88 QI"))b)1I=J ..'&*nn&@&@ / M
 &&11((667/0DEF  33T5H5HIH O@CIz[d@e \<	+_%$?!##,Y#7 KAx8}0 "KK(A(A3x=QE( AE@R@RV[@[S);%<ab
 #$4Q$7 8&--).).',z'9   &&t'>'>~z'Z['\* O++r#   )?'   ¡   ¿-:,%/.!c                     t        |      D ]O  \  }}|d   |z  |d<   |d   |z  |d<   | j                  dk(  s,|d   |v s4|dkD  s:||dz
     d   |d<   |d   |d<   Q |S )Nr]   r^   r5   r\   r   r[   )rd   r7   )r/   char_offsetsrm   supported_punctuationru   offsets         r$   ri   z$ParakeetProcessor._refine_timestamps   s     #<0 
	0IAv$Wo
:F7O"5MJ6F5M
 !!U*vgBW/W\]`a\a".q1u"5e"<w &wu
	0 r#   )z<blank>N)NN)r   r   r    r.   propertyr7   r   r   r   r
   listre   r	   r   rM   rO   rT   r_   ri   __classcell__)r2   s   @r$   r'   r'   ,   s    7$ V V  bf$(	// ++d9o=EV@WWZ^^/ Tz	/
 01/ /b O O< '+ 1h ?xr#   r'   N)tokenizers.decodersr   audio_utilsr   r   processing_utilsr   r   r	   tokenization_utils_baser
   r   utilsr   r   
get_loggerr   rB   r   r'   __all__r"   r#   r$   <module>r      se     - 9 H H C , 
		H	%.e " Y Y Yx 
r#   