o
    
j
                     @   s  d dl Z d dlZd dlZd dl mZ d dlmZ d dlmZ d dlZd dl	Z
d dlmZ dd Zdd
dZedkre jdedZejdedddd ejdedddd ejdedddd ejdedddd ejdeddd e Zeejejejejej dS dS )    N)RawTextHelpFormatter)Pool)copytree)tqdmc                 C   s,   | \}}t j||d\}}t||| d S )N)sr)librosaloadsfwrite)	func_argsfilename	output_sryr    r   C/home/kuhnn/.local/lib/python3.10/site-packages/TTS/bin/resample.pyresample_file   s   r   wav
   c           	   	   C   s   |rt d t| | |} t d tjtj| d| dd}t dt| d tt|t||g }t	|d0}t
t|d	}t|t|D ]\}}|  qLW d    n1 s_w   Y  W d    n1 snw   Y  t d
 d S )Nz'Recursively copying the input folder...zResampling the audio files...z**/*.T)	recursivezFound z	 files...)	processes)totalzDone !)printr   globospathjoinlenlistzipr   r   	enumerateimap_unorderedr   update)		input_dirr   
output_dirfile_extn_jobsaudio_filesppbar_r   r   r   resample_files   s"   

r*   __main__a  Resample a folder recusively with librosa
                       Can be used in place or create a copy of the folder as an output.


                       Example run:
                            python TTS/bin/resample.py
                                --input_dir /root/LJSpeech-1.1/
                                --output_sr 22050
                                --output_dir /root/resampled_LJSpeech-1.1/
                                --file_ext wav
                                --n_jobs 24
                    )descriptionformatter_classz--input_dirTz9Path of the folder containing the audio files to resample)typedefaultrequiredhelpz--output_sri"V  Fz9Samlple rate to which the audio files should be resampledz--output_dirzNPath of the destination folder. If not defined, the operation is done in placez
--file_extz(Extension of the audio files to resamplez--n_jobsz6Number of threads to use, by default it uses all cores)r.   r/   r1   )Nr   r   )argparser   r   r   multiprocessingr   shutilr   r   	soundfiler	   r   r   r*   __name__ArgumentParserparseradd_argumentstrint
parse_argsargsr"   r   r#   r$   r%   r   r   r   r   <module>   sd    

