§
     `ƒiï  ã                   óX   — d Z ddlmZ ddlZddlmZ ddlmZ  G d„ de¦  «        Z	dgZ
dS )	z)
Text/audio processor class for MusicGen
é    )ÚAnyNé   )ÚProcessorMixin)Úto_numpyc                   ój   ‡ — e Zd ZdZdZdZˆ fd„Zdd„Zˆ fd„Zd	„ Z	dd
e
deej                 fd„Zˆ xZS )ÚMusicgenProcessoral  
    Constructs a MusicGen processor which wraps an EnCodec feature extractor and a T5 tokenizer into a single processor
    class.

    [`MusicgenProcessor`] offers all the functionalities of [`EncodecFeatureExtractor`] and [`TTokenizer`]. See
    [`~MusicgenProcessor.__call__`] and [`~MusicgenProcessor.decode`] for more information.

    Args:
        feature_extractor (`EncodecFeatureExtractor`):
            An instance of [`EncodecFeatureExtractor`]. The feature extractor is a required input.
        tokenizer (`T5Tokenizer`):
            An instance of [`T5Tokenizer`]. The tokenizer is a required input.
    ÚEncodecFeatureExtractor)ÚT5TokenizerÚT5TokenizerFastc                 ór   •— t          ¦   «                              ||¦  «         | j        | _        d| _        d S )NF)ÚsuperÚ__init__Úfeature_extractorÚcurrent_processorÚ_in_target_context_manager)Úselfr   Ú	tokenizerÚ	__class__s      €ú„/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/models/musicgen/processing_musicgen.pyr   zMusicgenProcessor.__init__-   s7   ø€ Ý‰Œ×ÒÐ*¨IÑ6Ô6Ð6Ø!%Ô!7ˆÔØ*/ˆÔ'Ð'Ð'ó    NTc                 ó<   — | j                              |||¬¦  «        S )N)ÚtaskÚlanguageÚno_timestamps)r   Úget_decoder_prompt_ids)r   r   r   r   s       r   r   z(MusicgenProcessor.get_decoder_prompt_ids2   s    € ØŒ~×4Ò4¸$ÈÐanÐ4ÑoÔoÐor   c                 óš   •— | j         r | j        |i |¤ŽS t          |¦  «        dk    r|d         |d<    t          ¦   «         j        |i |¤ŽS )a  
        Forwards the `audio` argument to EncodecFeatureExtractor's [`~EncodecFeatureExtractor.__call__`] and the `text`
        argument to [`~T5Tokenizer.__call__`]. Please refer to the docstring of the above two methods for more
        information.
        r   Úaudio)r   r   Úlenr   Ú__call__)r   ÚargsÚkwargsr   s      €r   r   zMusicgenProcessor.__call__5   s`   ø€ ð Ô*ð 	;Ø)4Ô)¨4Ð:°6Ð:Ð:Ð:åˆt‰9Œ9qŠ=ˆ=Ø" 1œgˆF7‰OØu‰wŒwÔ Ð0¨Ð0Ð0Ð0r   c                 óú   — |                      dd¦  «        }|                      dd¦  «        }t          |¦  «        dk    r|d         }|dd…         }||                      ||¬¦  «        S  | j        j        |i |¤ŽS )ai  
        This method is used to decode either batches of audio outputs from the MusicGen model, or batches of token ids
        from the tokenizer. In the case of decoding token ids, this method forwards all its arguments to T5Tokenizer's
        [`~PreTrainedTokenizer.batch_decode`]. Please refer to the docstring of this method for more information.
        r   NÚpadding_maskr   é   )r#   )Úpopr   Ú_decode_audior   Úbatch_decode)r   r    r!   Úaudio_valuesr#   s        r   r'   zMusicgenProcessor.batch_decodeC   sˆ   € ð —z’z '¨4Ñ0Ô0ˆØ—z’z .°$Ñ7Ô7ˆåˆt‰9Œ9qŠ=ˆ=Ø œ7ˆLØ˜˜˜”8ˆDàÐ#Ø×%Ò% lÀÐ%ÑNÔNÐNà.4”>Ô.°Ð?¸Ð?Ð?Ð?r   r#   Úreturnc                 óê  — t          |¦  «        }|j        \  }}}|€t          |¦  «        S t          |¦  «        }||j        d         z
  }d| j        j        z
  }t          j        |dd|ffd|¬¦  «        }|                     ¦   «         }t          |¦  «        D ]Y}t          j	        ||         ¦  «        ||         ddd…f         | j        j        k             }	|	 
                    |d¦  «        ||<   ŒZ|S )zn
        This method strips any padding from the audio values to return a list of numpy audio arrays.
        Néÿÿÿÿr$   )r   r   r   Úconstant)Úconstant_values)r   ÚshapeÚlistr   Úpadding_valueÚnpÚpadÚtolistÚrangeÚasarrayÚreshape)
r   r(   r#   ÚbszÚchannelsÚseq_lenÚ
differencer0   ÚiÚsliced_audios
             r   r&   zMusicgenProcessor._decode_audioU   s	  € õ   Ñ-Ô-ˆØ!-Ô!3ÑˆˆXwàÐÝ˜Ñ%Ô%Ð%å Ñ-Ô-ˆð ˜|Ô1°"Ô5Ñ5ˆ
Ø˜DÔ2Ô@Ñ@ˆÝ”v˜l¨V°a¸°_Ð,EÀzÐcpÐqÑqÔqˆà#×*Ò*Ñ,Ô,ˆÝs‘”ð 	Að 	AˆAÝœ: l°1¤oÑ6Ô6Ø˜Q”  a a a Ô(¨DÔ,BÔ,PÒPôˆLð +×2Ò2°8¸RÑ@Ô@ˆL˜‰OˆOàÐr   )NNT)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úfeature_extractor_classÚtokenizer_classr   r   r   r'   r   r/   r1   Úndarrayr&   Ú__classcell__)r   s   @r   r   r      sÀ   ø€ € € € € ðð ð 8ÐØ8€Oð0ð 0ð 0ð 0ð 0ð
pð pð pð pð1ð 1ð 1ð 1ð 1ð@ð @ð @ð$ð ¸ð ÀtÈBÌJÔGWð ð ð ð ð ð ð ð r   r   )r@   Útypingr   Únumpyr1   Úprocessing_utilsr   Úutilsr   r   Ú__all__© r   r   ú<module>rK      s”   ððð ð Ð Ð Ð Ð Ð à Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .Ø Ð Ð Ð Ð Ð ðSð Sð Sð Sð S˜ñ Sô Sð Sðl Ð
€€€r   