o
    Siu,                     @   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 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
Zdddefdedee dee dee def
ddZ			ddedee dee dee de
eeeef f f
ddZdedefddZdS )a  
This CSTR VCTK Corpus includes speech data uttered by 110 English
speakers with various accents. Each speaker reads out about 400
sentences, which were selected from a newspaper, the rainbow passage
and an elicitation paragraph used for the speech accent archive.

The newspaper texts were taken from Herald Glasgow, with permission
from Herald & Times Group. Each speaker has a different set of the
newspaper texts selected based a greedy algorithm that increases the
contextual and phonetic coverage. The details of the text selection
algorithms are described in the following paper:

C. Veaux, J. Yamagishi and S. King,
"The voice bank corpus: Design, collection and data analysis of
a large regional accent speech database,"
https://doi.org/10.1109/ICSDA.2013.6709856

The rainbow passage and elicitation paragraph are the same for all
speakers. The rainbow passage can be found at International Dialects
of English Archive:
(http://web.ku.edu/~idea/readings/rainbow.htm). The elicitation
paragraph is identical to the one used for the speech accent archive
(http://accent.gmu.edu). The details of the the speech accent archive
can be found at
http://www.ualberta.ca/~aacl2009/PDFs/WeinbergerKunath2009AACL.pdf

All speech data was recorded using an identical recording setup: an
omni-directional microphone (DPA 4035) and a small diaphragm condenser
microphone with very wide bandwidth (Sennheiser MKH 800), 96kHz
sampling frequency at 24 bits and in a hemi-anechoic chamber of
the University of Edinburgh. (However, two speakers, p280 and p315
had technical issues of the audio recordings using MKH 800).
All recordings were converted into 16 bits, were downsampled to
48 kHz, and were manually end-pointed.

This corpus was originally aimed for HMM-based text-to-speech synthesis
systems, especially for speaker-adaptive HMM-based speech synthesis
that uses average voice models trained on multiple speakers and speaker
adaptation technologies. This corpus is also suitable for DNN-based
multi-speaker text-to-speech synthesis systems and waveform modeling.

COPYING

This corpus is licensed under the Creative Commons License: Attribution 4.0 International
http://creativecommons.org/licenses/by/4.0/legalcode

VCTK VARIANTS
There are several variants of the VCTK corpus:
Speech enhancement
- Noisy speech database for training speech enhancement algorithms and TTS models where we added various types of noises to VCTK artificially: http://dx.doi.org/10.7488/ds/2117
- Reverberant speech database for training speech dereverberation algorithms and TTS models where we added various types of reverberantion to VCTK artificially http://dx.doi.org/10.7488/ds/1425
- Noisy reverberant speech database for training speech enhancement algorithms and TTS models http://dx.doi.org/10.7488/ds/2139
- Device Recorded VCTK where speech signals of the VCTK corpus were played back and re-recorded in office environments using relatively inexpensive consumer devices http://dx.doi.org/10.7488/ds/2316
- The Microsoft Scalable Noisy Speech Dataset (MS-SNSD) https://github.com/microsoft/MS-SNSD

ASV and anti-spoofing
- Spoofing and Anti-Spoofing (SAS) corpus, which is a collection of synthetic speech signals produced by nine techniques, two of which are speech synthesis, and seven are voice conversion. All of them were built using the VCTK corpus. http://dx.doi.org/10.7488/ds/252
- Automatic Speaker Verification Spoofing and Countermeasures Challenge (ASVspoof 2015) Database. This database consists of synthetic speech signals produced by ten techniques and this has been used in the first Automatic Speaker Verification Spoofing and Countermeasures Challenge (ASVspoof 2015) http://dx.doi.org/10.7488/ds/298
- ASVspoof 2019: The 3rd Automatic Speaker Verification Spoofing and Countermeasures Challenge database. This database has been used in the 3rd Automatic Speaker Verification Spoofing and Countermeasures Challenge (ASVspoof 2019) https://doi.org/10.7488/ds/2555


ACKNOWLEDGEMENTS

The CSTR VCTK Corpus was constructed by:

        Christophe Veaux   (University of Edinburgh)
        Junichi Yamagishi  (University of Edinburgh)
        Kirsten MacDonald

The research leading to these results was partly funded from EPSRC
grants EP/I031022/1 (NST) and EP/J002526/1 (CAF), from the RSE-NSFC
grant (61111130120), and from the JST CREST (uDialogue).

Please cite this corpus as follows:
Christophe Veaux,  Junichi Yamagishi, Kirsten MacDonald,
"CSTR VCTK Corpus: English Multi-speaker Corpus for CSTR Voice Cloning Toolkit",
The Centre for Speech Technology Research (CSTR),
University of Edinburgh
    N)defaultdict)Path)DictOptionalUnion)	RecordingRecordingSetSupervisionSegmentSupervisionSet$validate_recordings_and_supervisions)fix_manifests)Pathlikeresumable_downloadzKhttps://datashare.ed.ac.uk/bitstream/handle/10283/3443/VCTK-Corpus-0.92.zipz4http://www.udialogue.org/download/VCTK-Corpus.tar.gz.F
target_dirforce_downloaduse_edinburgh_vctk_urlurlreturnc           
      C   s   t | } | jddd |rt}|dd }| | }| |dddd }|d }| r<td	| d
| d |S t|||d t	j
|dd |drRtjntj}||}	|	j| d W d   n1 sjw   Y  |  |S )a]  
    Download and untar/unzip the VCTK 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.
    :param url: str, the url of tarred/zipped VCTK corpus.
    :return: the path to downloaded and extracted directory with data.
    Tparentsexist_ok/z.zip z.tar.gzz
.completedz	Skipping z	 because z exists.)filenamer   )ignore_errors)pathN)r   mkdirEDINBURGH_VCTK_URLsplitreplaceis_filelogginginfor   shutilrmtreeendswithzipfileZipFiletarfileopen
extractalltouch)
r   r   r   r   archive_namearchive_pathpart_dircompleted_detectoropenerarchive r4   G/home/ubuntu/.local/lib/python3.10/site-packages/lhotse/recipes/vctk.pydownload_vctkh   s.   
r6   mic2
corpus_dir
output_dirmic_idc                 C   s  t | } |  sJ d|  t| |}d}d}|r,| d }tdd |dD }n| d }tdd |d	D }g }| d
 dD ]w}|  }	|j	dd }
|j
}d}|rm|
dkrf|dkrfqF|d | }n|}|
dkr||vrxqF|| jd j}t | sqF||
tdd }|du rtd|
 d |t||d|| j|	d|
|d |d |d |d dd	 qFt|}t||\}}t|| |durt |}|jddd ||d  ||d   ||d!S )"a  
    Prepares and returns the L2 Arctic manifests which consist of Recordings and Supervisions.

    :param corpus_dir: Pathlike, the path of the data dir.
    :param output_dir: Pathlike, the path where to write the manifests.
    :param use_edinburgh_vctk_url: Bool, if use edinburgh_vctk_url to download the dataset, please set it as True.
    :param mic_id: str, the default of mic_id is mic2.
    :return: a dict with keys "read" and "spontaneous".
        Each hold another dict of {'recordings': ..., 'supervisions': ...}

    Note: when download the vctk dataset with the edinburgh url, there are some points should know:
        * All the speeches from speaker ``p315`` will be skipped due to the lack of the corresponding text files.
        * All the speeches from speaker ``p280`` will be skipped for ``mic_id="mic2"`` due to the lack of the audio files.
        * Some of the speeches from speaker ``p362`` will be skipped due to the lack of  the audio files.
        * See Also: https://datashare.is.ed.ac.uk/handle/10283/3443
    zNo such directory: r   wav48_silence_trimmedc                 s       | ]}t |V  qd S Nr   	from_file).0flacr4   r4   r5   	<genexpr>       

zprepare_vctk.<locals>.<genexpr>z*.flacwav48c                 s   r<   r=   r>   )r@   wavr4   r4   r5   rB      rC   z*.wavtxtz*.txt_r   p280r7   p362c                   S   s   d S r=   r4   r4   r4   r4   r5   <lambda>   s    zprepare_vctk.<locals>.<lambda>Nz!Cannot find metadata for speaker r   Englishgenderaccentageregion)rM   rN   rO   )	idrecording_idstartdurationtextlanguagespeakerrL   customTr   zvctk_recordings_all.jsonl.gzzvctk_supervisions_all.jsonl.gz)
recordingssupervisions)r   is_dir_parse_speaker_descriptionr   from_recordingsrglob	read_textstripnamer    stemsourcessourcer"   getr   r#   warningappendr	   rS   r
   from_segmentsr   r   r   to_file)r8   r9   r   r:   speaker_meta
audios_dirrX   rY   r   rT   rV   seg_idaudio_file_idaudio_file_pathmetar4   r4   r5   prepare_vctk   sv   






ro   c           
      C   s   i }dd | d    D }|d }tg dt|s J |dd  D ]#^}}}}}	t||||	d ur;d|	nd d||sFd	| n| < q&|S )
Nc                 S   s   g | ]}|  qS r4   )r    )r@   liner4   r4   r5   
<listcomp>   s    z._parse_speaker_description.<locals>.<listcomp>zspeaker-info.txtr   )IDAGEGENDERACCENTSREGION    )rN   rL   rM   rO   p)r^   
splitlinessetissubsetintjoin)
r8   r   rn   linesheaderspkrN   rL   rM   rO   r4   r4   r5   r[      s   r[   )NFr7   )__doc__r#   r%   r*   r(   collectionsr   pathlibr   typingr   r   r   lhotser   r   r	   r
   r   	lhotse.qar   lhotse.utilsr   r   r   CREST_VCTK_URLboolstrr6   ro   r[   r4   r4   r4   r5   <module>   sX    O
*
b