o
    rqi                     @   s  d dl Z 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
mZ zd dlmZ W n ey;   edw dZe Zd	edd
ddd ddf	ddZedkre  Zejdd	dd ejdeed ejdeddd ejddd ejddd ejdd
dd ejd edd ejd!edd"d ejd#edd$d ejd%d&d'd(d) ejd*d&d+d,d) ejd-d.d'd/d) ejd0d.d+d1d) ejd2d3 ejdd4 e Zeej eejejejej ej!ej"ej#ej$ej%ej&ej\Z'Z(ed5e'  ed6e(  dS dS )7    N)check_local_model_is_latest)snapshot_download)
ThirdParty)
get_logger)AutoLabelingzpls install tts-autolabel with                       "pip install tts-autolabel -f                       https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html"zdamo/speech_ptts_autolabel_16kallZfemale      Fc                 C   s   t j| std|  dt j|std| dddd}|||}tt j| |dt j||||	||||
d}| \}}||fS )	Nzinput_wav:  not existsz
work_dir: c                 S   s   t j| rt j| r| nt j| }t|tjdid n
t| |tjdid}t j|s6t	d| dt j
|d}t j|sKt	d| dt|}|| t j
|d}|S )	NZspeech_tts_autolabel)
user_agent)revisionr   zmodel_cache_dir: r
   z	model.zipz
zip_file: model)ospathexistsisdirdirnamer   r   ZKEYr   
ValueErrorjoinzipfileZipFile
extractall)r   Zmodel_revisionZmodel_cache_dirzip_filezZtarget_resource r   l/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/modelscope/tools/speech_tts_autolabel.py_download_and_unzip_resource*   s0   


z4run_auto_label.<locals>._download_and_unzip_resourceF
enable_enh)N)r   r   r   r   r   abspathrun)	input_wavwork_dirpara_idsZresource_model_idresource_revisiongenderstageprocess_numdevelop_modehas_parar   r   Zmodel_resourceZauto_labelingret_codereportr   r   r   run_auto_label   s.   


r,   __main__z
--para_idszyou can use this variable to config your auto labeling paragraph ids,         all means all in the dir, none means no paragraph 1 means 1 para only,         1 2 means 1 and 2, transcipt/prosody/wav should be named exactly the same!!!)defaulthelpz
--resource)typer.   z--resource_revisionzresource directory)r0   r.   r/   z--input_wavzpersonal user input wav dir)r/   z
--work_dirzautolabel work dirz--genderzpersonal user genderz--develop_modez--stagez?auto labeling stage, 0 means qualification and 1 means labelingz--process_numz+kaldi bin parallel execution process numberz
--has_parar)   
store_trueZ	paragraph)destactionr/   z	--no_parastore_falsezno paragraphz--enable_enhr   zenable audio enhancementz--disable_enhzdisable audio enhancementT)r)   r   z	ret_code=zreport=))argparser   sysr   Zmodelscope.hub.check_modelr   Z modelscope.hub.snapshot_downloadr   Zmodelscope.utils.constantr   Zmodelscope.utils.loggerr   Ztts_autolabelr   ImportErrorZDEFAULT_RESOURCE_MODEL_IDloggerr,   __name__ArgumentParserparseradd_argumentstrintset_defaults
parse_argsargsinfor   r!   r"   r#   resourcer$   r%   r&   r'   r(   r)   r*   r+   r   r   r   r   <module>   s    

8
