
    Vh
                     `    d Z ddlZddlZddlZddlZddlZddlm	Z	  G d d          Z
d
d	ZdS )z@Utility for on the fly pitch/tempo change for data augmentation.    N   )
save_audioc                   4    e Zd ZdZdddddgdfdZd	 Zd
 ZdS )RepitchedWrapperzA
    Wrap a dataset to apply online change of pitch / tempo.
    g?            Tc                 h    || _         || _        || _        || _        || _        || _        || _        d S N)datasetproba	max_pitch	max_tempo	tempo_stdsamevocals)selfr   r   r   r   r   r   r   s           T/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/demucs/repitch.py__init__zRepitchedWrapper.__init__   s7    
"""	    c                 *    t          | j                  S r   )lenr   )r   s    r   __len__zRepitchedWrapper.__len__    s    4<   r   c                 r   | j         |         }|j        d         }t          dd| j        z  z
  |z            }t	          j                    | j        k     rg }t          |          D ]\  }}|dk    s| j        sct	          j        | j	         | j	                  }t	          j
        d| j                  }	t          t          | j         |	          | j                  }	t          |||	|| j        v           }|                    |d d d |f                    t#          j        |          }n|dd |f         }|S )Nr   g{Gz?r   )voice.)r   shapeintr   randomr   	enumerater   randintr   gaussr   minmaxrepitchr   appendtorchstack)
r   indexstreams	in_length
out_lengthoutsidxstreamdelta_pitchdelta_tempos
             r   __getitem__zRepitchedWrapper.__getitem__#   s;   ,u%M"%	!dT^33y@AA
=??TZ''D(11 
4 
4V!88498"(.$.$."Q"QK"(,q$."A"AK"%c4>/;&G&G"X"XK ,	. . .
 F111kzk>23333k$''GGc;J;./Gr   N)__name__
__module____qualname____doc__r   r   r3    r   r   r   r      sb          '*Q"aSt   ! ! !    r   r   FD  c                    t          j        d          }t          j        d          }t          | |j        |d           d|j        |j        d| d|dg}|r|d	gz  }|r|d
gz  }	 t	          j        |dd           nA# t          j        $ r/}	t          d|	j        	                    d                     d}	~	ww xY wt          j        |j                  \  } }
|
|k    sJ | S )z
    tempo is a relative delta in percentage, so tempo=10 means tempo at 110%!
    pitch is in semi tones.
    Requires `soundstretch` to be installed, see
    https://www.surina.net/soundtouch/soundstretch.html
    z.wav)suffixclamp)clipsoundstretchz-pitch=z-tempo=z.6fz-quickz-speechT)capture_outputcheckzCould not change bpm because zutf-8N)tempfileNamedTemporaryFiler   namesprunCalledProcessErrorRuntimeErrorstderrdecodetaload)wavpitchtempor   quick
samplerateinfileoutfilecommanderrorsrs              r   r&   r&   ;   s2    (777F)888GsFK'::::%%G  H: I;[
wt488888  [ [ [Y5<;N;Nw;W;WYYZZZ[ggl##GCJs   ,B C*B==C)FFr9   )r7   r    
subprocessrD   rA   r(   
torchaudiorJ   audior   r   r&   r8   r   r   <module>rY      s    G F                 & & & & & & & &R     r   