
    i                      ^    d Z ddlmZ ddlZddlmZ ddlmZm	Z	 e G d de             Z
dgZy)	z)
Text/audio processor class for MusicGen
    )AnyN   )ProcessorMixin)auto_docstringto_numpyc                   l     e Zd Z fdZddZe fd       Zd Zd	dede	e
j                     fdZ xZS )
MusicgenProcessorc                 &    t         |   ||       y N)super__init__)selffeature_extractor	tokenizer	__class__s      l/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/transformers/models/musicgen/processing_musicgen.pyr   zMusicgenProcessor.__init__   s    *I6    c                 >    | j                   j                  |||      S )N)tasklanguageno_timestamps)r   get_decoder_prompt_ids)r   r   r   r   s       r   r   z(MusicgenProcessor.get_decoder_prompt_ids   s    ~~44$an4oor   c                 N    t        |      dkD  r|d   |d<   t        |   |i |S )Nr   audio)lenr   __call__)r   argskwargsr   s      r   r   zMusicgenProcessor.__call__"   s0    t9q="1gF7Ow000r   c                     |j                  dd      }|j                  dd      }t        |      dkD  r
|d   }|dd }|| j                  ||      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_decode(   s{     zz'40zz.$7t9q=7L8D#%%l%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|      }|j                         }t        |      D ]S  }t        j                  ||         ||   dddf   | j                  j                  k7     }	|	j                  |d      ||<   U |S )zn
        This method strips any padding from the audio values to return a list of numpy audio arrays.
        Nr!   )r   r   r   constant)constant_values)r   shapelistr   padding_valuenppadtolistrangeasarrayreshape)
r   r%   r    bszchannelsseq_len
differencer-   isliced_audios
             r   r#   zMusicgenProcessor._decode_audio:   s     -!-!3!3Xw%%- |11"55
D22@@@vvlVa_,Ezcpq#**,s 	AA::l1o6Qa(D,B,B,P,PPL +228R@LO		A r   )NNTr   )__name__
__module____qualname__r   r   r   r   r$   r   r,   r.   ndarrayr#   __classcell__)r   s   @r   r	   r	      sD    7p 1 1
@$ tBJJGW r   r	   )__doc__typingr   numpyr.   processing_utilsr   utilsr   r   r	   __all__ r   r   <module>rF      s>      . - 8 8 8v 
r   