
    riK              	           S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  Sr
Sr\R                  " S5      r\R                  " \5      rSS	 jrSS
 jr SS\S\S\SS4S jjrS\S\4S jr\S:X  a  \" 5         gg)z2Command-line utility for downloading Piper voices.    N)Path)urlopenzhttps://huggingface.co/rhasspy/piper-voices/resolve/main/{lang_family}/{lang_code}/{voice_name}/{voice_quality}/{lang_code}-{voice_name}-{voice_quality}{extension}?download=truezRhttps://huggingface.co/rhasspy/piper-voices/resolve/main/voices.json?download=truez[^(?P<lang_family>[^-]+)_(?P<lang_region>[^-]+)-(?P<voice_name>[^-]+)-(?P<voice_quality>.+)$returnc                     [         R                  " 5       n U R                  SSSS9  U R                  SSSSS	S
9  U R                  SSSSS9  U R                  SSSS9  U R                  5       n[        R
                  " UR                  (       a  [        R                  O[        R                  S9  UR                  (       d  [        5         gUR                  (       a  [        UR                  5      nO[        R                  " 5       nUR                  SSS9  UR                   H  n[        X2UR                   S9  M     g)zDownload Piper voices.voice*z(Name of voice like 'en_US-lessac-medium')nargshelpz--download-dirz--download_dirz
--data-dirz
--data_dirz>Directory to download voices into (default: current directory))r
   z--force-redownloadz--force_redownload
store_truez=Force redownloading of voice files even if they exist already)actionr
   z--debugzPrint DEBUG logs to console)levelNT)parentsexist_ok)force_redownload)argparseArgumentParseradd_argument
parse_argsloggingbasicConfigdebugDEBUGINFOr   list_voicesdownload_dirr   cwdmkdirdownload_voicer   )parserargsr   r   s       [/home/kim/smarthome/piper_models/venv/lib/python3.13/site-packages/piper/download_voices.pymainr"      s   $$&F
s!K   M   L	   ,-J   Dtzzgmmw||L::D--.xxztd3uT=R=RS     c                     [         R                  S[        5        [        [        5       n [        R
                  " U 5      nSSS5        [        WR                  5       5       H  n[        U5        M     g! , (       d  f       N:= f)zList available voices and exit.z"Downloading voices.json file: '%s'N)	_LOGGERr   VOICES_JSONr   jsonloadsortedkeysprint)responsevoices_dictr   s      r!   r   r   B   sX    MM6D		ii) 
 ((*+e , 
	s   A55
Br   r   r   c                 j   U R                  5       n [        R                  U 5      nU(       d  [        SU  S35      eUR	                  S5      nUS-   UR	                  S5      -   nUR	                  S5      nUR	                  S5      nU SU SU 3nUUUUS	.n	X S
3-  n
U(       d  [        U
5      (       a  [        R                  " SSS
0U	D6n[        R                  SX5        [        U5       n[        U
S5       n[        R                  " X5        SSS5        SSS5        [        R                  SU
5        X S3-  nU(       d  [        U5      (       a  [        R                  " SSS0U	D6n[        R                  SX5        [        U5       n[        US5       n[        R                  " UU5        SSS5        SSS5        [        R                  SU5        [        R                  SU 5        g! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       Ne= f! , (       d  f       Nn= f)z6Download a voice model and config file to a directory.zVoice 'zO' did not match pattern: <language>-<name>-<quality> like 'en_US-lessac-medium'lang_family_lang_region
voice_namevoice_quality-)r/   	lang_coder2   r3   z.onnx	extensionz#Downloading model from '%s' to '%s'wbNzDownloaded: '%s'z
.onnx.jsonz$Downloading config from '%s' to '%s'zDownloaded: %s )stripVOICE_PATTERNmatch
ValueErrorgroup_needs_download
URL_FORMATformatr%   r   r   openshutilcopyfileobjinfo)r   r   r   voice_matchr/   r5   r2   r3   
voice_codeformat_args
model_path	model_urlr,   
model_fileconfig_path
config_urlconfig_files                    r!   r   r   L   s    KKME%%e,KeWkl
 	
 ##M2Kc!K$5$5m$DDI""<0J%%o6M;a
|1]O<J" &	K ,e 44J?:66%%GG;G	;YSY8j$':""88 (   	(*5<z!::K?;77&&MMM
<jVZ Hk4(K""8[9 ) ! 	(+6LL!5) ('   )( ! sH   .H;G1HH$H4H$1
G?	;H
H
H!	H$$
H2pathc                 n    U R                  5       (       d  gU R                  5       R                  S:X  a  gg)z+Return True if file needs to be downloaded.Tr   F)existsstatst_size)rN   s    r!   r>   r>   {   s*    ;;==yy{ar#   __main__)r   N)F)__doc__r   r'   r   rerB   pathlibr   urllib.requestr   r?   r&   compiler:   	getLogger__name__r%   r"   r   strboolr   r>   r8   r#   r!   <module>r]      s    8    	   " A
X  

b 

H
%&TX >C,*,*",*6:,*	,*^	$ 	4 	 zF r#   