o
    
j                     @   s   d dl Z d dlZd dlmZmZmZmZ d dlZd dl	Z	d dl
mZ G dd dejZG dd deZ		dd	ed
eeee	jeeee	jf eee	jf f f dedefddZ	dddZdS )    N)AnyCallableDictUnion)get_user_data_dirc                           e Zd ZdZ fddZ  ZS )RenamingUnpicklerz9Overload default pickler to solve module renaming problemc                    s   t  |dd|S )Nmozilla_voice_ttsTTS)super
find_classreplace)selfmodulename	__class__ ?/home/kuhnn/.local/lib/python3.10/site-packages/TTS/utils/io.pyr      s   zRenamingUnpickler.find_class)__name__
__module____qualname____doc__r   __classcell__r   r   r   r   r      s    r   c                       r   )AttrDictz>A custom dict which converts dict keys
    to class attributesc                    s   t  j|i | | | _d S )N)r   __init____dict__)r   argskwargsr   r   r   r      s   
zAttrDict.__init__)r   r   r   r   r   r   r   r   r   r   r      s    r   Tpathmap_locationcachereturnc                 K   s   t j| pt j| }|r>|s>tjd|  dttdidd}tj	|fd|i|W  d   S 1 s7w   Y  dS t| d}tj	|fd|i|W  d   S 1 sZw   Y  dS )a  Like torch.load but can load from other locations (e.g. s3:// , gs://).

    Args:
        path: Any path or url supported by fsspec.
        map_location: torch.device or str.
        cache: If True, cache a remote file locally for subsequent calls. It is cached under `get_user_data_dir()/tts_cache`. Defaults to True.
        **kwargs: Keyword arguments forwarded to torch.load.

    Returns:
        Object stored in path.
    zfilecache::cache_storage	tts_cacherb)	filecachemoder    N)
osr   isdirisfilefsspecopenstrr   torchload)r   r    r!   r   is_localfr   r   r   load_fsspec   s   $$r2   Fc              	   C   sv   zt |td|d}W n ty#   tt_t |tdt|d}Y nw | |d  |r1|   |r7| 	  | |fS )Ncpu)r    r!   )r    pickle_moduler!   model)
r2   r.   deviceModuleNotFoundErrorr   
pickle_tts	Unpicklerload_state_dictcudaeval)r5   checkpoint_pathuse_cudar<   r!   stater   r   r   load_checkpoint9   s   r@   )NT)FFF)r(   pickler8   typingr   r   r   r   r+   r.   TTS.utils.generic_utilsr   r9   r   dictr   r-   r6   boolr2   r@   r   r   r   r   <module>   s*    ,
