o
    Si]                     @   s   d Z 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
mZmZmZmZ ddlmZ ddlmZmZ dZ			
ddededefddZ	ddedee fddZdS )a"  
ADEPT: A Dataset for Evaluating Prosody Transfer
Torresquintero, Alexandra; Teh, Tian Huey; Wallis, Christopher G. R.; Staib, Marlene; Mohan, Devang S Ram;
Hu, Vivian; Foglianti, Lorenzo; Gao, Jiameng; King, Simon

The ADEPT dataset consists of prosodically-varied natural speech samples for evaluating prosody transfer in
english text-to-speech models. The samples include global variations reflecting emotion and interpersonal
attitude, and local variations reflecting topical emphasis, propositional attitude, syntactic phrasing and
marked tonicity.

Txt and wav files are organised according to the folder structure
{speech_class}/{subcategory_or_interpretation}/{filename}, where filename follows the naming convention
{speaker}_{utterance_id}. Speakers comprise 'ad00' (female voice) and 'ad01' (male voice). For classes
with multiple interpretations, we provide the interpretations used in the disambiguation tasks in
'adept_prompts.json'.

The corpus only includes prosodic variations that listeners are able to distinguish with reasonable accuracy,
and we report these figures as a benchmark against which text-to-speech prosody transfer can be compared.
More details can be found in pre-print about the dataset (https://arxiv.org/abs/2106.08321).

Source: https://zenodo.org/record/5117102#.YVsHlS-B3T9
    N)Path)Optional)	RecordingRecordingSetSupervisionSegmentSupervisionSet$validate_recordings_and_supervisions)fix_manifests)Pathlikeresumable_downloadz1https://zenodo.org/record/5117102/files/ADEPT.zip.F
target_dirforce_downloadreturnc                 C   s   t | } | jddd | d }|d }| r"td| d |S d}| | }tt||d tj|dd	 t	
|}|j|d
 W d   n1 sLw   Y  |  |S )a  
    Download and untar the ADEPT dataset.

    :param target_dir: Pathlike, the path of the dir to storage the dataset.
    :param force_download: Bool, if True, download the tars no matter if the tars exist.
    :return: the path to downloaded and extracted directory with data.
    T)parentsexist_okADEPTz
.completedz#Skipping downloading ADEPT because z exists.z	ADEPT.zip)filenamer   )ignore_errors)pathN)r   mkdiris_filelogginginfor   	ADEPT_URLshutilrmtreezipfileZipFile
extractalltouch)r   r   
corpus_dircompleted_detectorzip_namezip_pathzip_f r&   H/home/ubuntu/.local/lib/python3.10/site-packages/lhotse/recipes/adept.pydownload_adept+   s    r(   r!   
output_dirc                 C   s  t | } |  sJ d|  tdd | d dD }g }t| d }t|}W d   n1 s6w   Y  | d d	D ]Y}t|	|j
j
j
dd
 d\}}}	d|	dd  }
d|||	f}||}|rv||	 | nd}|| }|||	d}|r||d< |t||d|jd| d|
|d	 qBt|}t||\}}t|| |durt |}||d  ||d  ||dS )a  
    Returns the manifests which consist of the Recordings and Supervisions.
    When all the manifests are available in the ``output_dir``, it will simply read and return them.

    :param corpus_dir: Pathlike, the path of the data dir.
    :param dataset_parts: string or sequence of strings representing dataset part names,
        e.g. 'train-clean-100', 'train-clean-5', 'dev-clean'.
        By default we will infer which parts are available in ``corpus_dir``.
    :param output_dir: Pathlike, the path where to write the manifests.
    :return: a Dict whose key is the dataset part, and the value is Dicts with the keys 'audio' and 'supervisions'.
    zNo such directory: c                 s   s>    | ]}t j|t||jjjd d dddV  qd S )N/_)r   recording_id)r   	from_filestrrelative_toparentreplace).0r   r&   r&   r'   	<genexpr>]   s    
z prepare_adept.<locals>.<genexpr>	wav_44khzz*.wavzadept_prompts.jsonNtxtz*.txtr*   r+   ADEPT_r,   r   )typelabel	prompt_idtextEnglish)	idr-   startdurationchannelr;   languagespeakercustomzadept_supervisions_all.jsonl.gzzadept_recordings_all.jsonl.gz)
recordingssupervisions)r   is_dirr   from_recordingsrglobopenjsonloadr/   r0   r1   splitjoingetappendr   r?   	read_textr   from_segmentsr	   r   to_file)r!   r)   rD   rE   finterpretation_mapr   annotation_typer9   r:   
speaker_idr-   interpretation_groupinterpretation	recordingrC   r&   r&   r'   prepare_adeptK   s^   




rZ   )r   F)N)__doc__rJ   r   r   r   pathlibr   typingr   lhotser   r   r   r   r   	lhotse.qar	   lhotse.utilsr
   r   r   boolr(   rZ   r&   r&   r&   r'   <module>   s4    
"