o
    Si                     @   s   d 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 ddl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dedeee
f fddZdedefddZdS )a  
DailyTalk: Spoken Dialogue Dataset for Conversational Text-to-Speech

Abstract: The majority of current TTS datasets, which are collections of individual utterances, contain few conversational aspects in terms of both style and metadata. In this paper, we introduce DailyTalk, a high-quality conversational speech dataset designed for Text-to-Speech. We sampled, modified, and recorded 2,541 dialogues from the open-domain dialogue dataset DailyDialog which are adequately long to represent context of each dialogue. During the data construction step, we maintained attributes distribution originally annotated in DailyDialog to support diverse dialogue in DailyTalk. On top of our dataset, we extend prior work as our baseline, where a non-autoregressive TTS is conditioned on historical information in a dialog. We gather metadata so that a TTS model can learn historical dialog information, the key to generating context-aware speech. From the baseline experiment results, we show that DailyTalk can be used to train neural text-to-speech models, and our baseline can represent contextual information. The DailyTalk dataset and baseline code are freely available for academic use with CC-BY-SA 4.0 license.

Paper: https://arxiv.org/abs/2207.01063
GitHub: https://github.com/keonlee9420/DailyTalk
    N)Path)Tuple)RecordingSetSupervisionSegmentSupervisionSet$validate_recordings_and_supervisions)fix_manifests)	load_json)Pathlikeis_module_availablezRhttps://drive.google.com/file/d/1nPrfJn3TcIVPc0Uf5tiAXUYLJceb_5k-/view?usp=sharingF
target_dirforce_downloadreturnc                 C   s   t dstdddl}t| } | jddd | d }|d}|s/| r/t| d	 ntd
t	  |j
t	t|ddd | rH|rotd| d|   t|}|j| d W d   |S 1 sjw   Y  |S )aD  
    Downloads the DailyTalk data from the Google Drive and extracts it.
    :param target_dir: the directory where DailyTalk data will be saved.
    :param force_download: if True, it will download the DailyTalk data even if it is already present.
    :return: the path to downloaded and extracted directory with data.
    gdownz5Please run 'pip install gdown' to download DailyTalk.r   NT)parentsexist_ok	dailytalkz.zipz# already exists. Skipping download.zRunning: gdown --fuzzy F)fuzzyquietzExtracting z to path)r   
ValueErrorr   r   mkdirwith_suffixexistslogginginfoDAILY_TALK_URLdownloadstrzipfileZipFile
extractall)r   r   r   
corpus_dir
corpus_zipzf r&   M/home/ubuntu/.local/lib/python3.10/site-packages/lhotse/recipes/daily_talk.pydownload_daily_talk   s&   

r(      r#   
output_dirnum_jobsc                 C   s^  t | } | d }| d }tj|d|td}g }t| D ]^\}}| D ]U\}	}
d|	 d|
d  d| }|
d d	v sEJ d
|
d  |td|
d  |d|| jd|
d dd|
d  |
d dkrgdnd|
d |
d |
d |
d dd
 q%qt	
|}t||\}}t||d |durt |}|jddd ||d  ||d  ||fS ) ah  
    Create RecordingSet and SupervisionSet manifests for DailyTalk from a raw corpus distribution.

    :param corpus_dir: Pathlike, the path to the extracted corpus.
    :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metadata.jsondataz*.wav)r+   recording_id
dailytalk__speaker_d)r   r)   zUnknown speaker index: indexg        r   textEnglishdailytalk_spkr)   FMturntopicemotionact)r8   r9   r:   r;   )
idr-   startdurationchannelr3   languager0   gendercustom)
recordingssupervisionsNT)r   r   z!dailytalk_recordings_all.jsonl.gzz#dailytalk_supervisions_all.jsonl.gz)r   r   from_dirmake_recording_idr	   itemsappendr   r>   r   from_segmentsr   r   r   to_file)r#   r*   r+   metar,   rC   rD   
dialog_idxdialogutt_idxuttr-   r&   r&   r'   prepare_daily_talk=   sV   
rP   r   c                 C   s   d| j  S )Nr.   )stemr   r&   r&   r'   rF   z   s   rF   )F)Nr)   )__doc__r   r    pathlibr   typingr   lhotser   r   r   r   	lhotse.qar   lhotse.serializationr	   lhotse.utilsr
   r   r   boolr(   intrP   r   rF   r&   r&   r&   r'   <module>   s0    "

=