o
    Ni
                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZddl	m
  mZ ddlmZ dZdZdZd	Zed
 ed ed ed ed ed ed dZG dd dejjZdd Zdd Zdd ZdS )LibriTTS dataset.    )absolute_import)division)print_functionNaG  @inproceedings{zen2019libritts,
  title = {LibriTTS: A Corpus Derived from LibriSpeech for Text-to-Speech},
  author = {H. Zen and V. Dang and R. Clark and Y. Zhang and R. J. Weiss and Y. Jia and Z. Chen and Y. Wu},
  booktitle = {Proc. Interspeech},
  month = sep,
  year = {2019},
  doi = {10.21437/Interspeech.2019-2441},
}
a  LibriTTS is a multi-speaker English corpus of approximately 585 hours of read
English speech at 24kHz sampling rate, prepared by Heiga Zen with the assistance
of Google Speech and Google Brain team members. The LibriTTS corpus is designed
for TTS research. It is derived from the original materials (mp3 audio files
from LibriVox and text files from Project Gutenberg) of the LibriSpeech corpus.
The main differences from the LibriSpeech corpus are listed below:

1. The audio files are at 24kHz sampling rate.
2. The speech is split at sentence breaks.
3. Both original and normalized texts are included.
4. Contextual information (e.g., neighbouring sentences) can be extracted.
5. Utterances with significant background noise are excluded.
zhttp://www.openslr.org/60z$http://www.openslr.org/resources/60/zdev-clean.tar.gzzdev-other.tar.gzztest-clean.tar.gzztest-other.tar.gzztrain-clean-100.tar.gzztrain-clean-360.tar.gzztrain-other-500.tar.gz)	dev_clean	dev_other
test_clean
test_othertrain_clean100train_clean360train_other500c                   @   s<   e Zd ZdZejdZdd Zdd Z	dd Z
d	d
 ZdS )Librittsr   z1.0.1c                 C   sX   t jj| tt jt jjdddt j t j tj	tj	tj
ddttt jjdddS )Nwavi]  )file_formatsample_rate)speechtext_originaltext_normalized
speaker_id
chapter_idid)r   r   )r   )builderdescriptionfeaturessupervised_keyshomepagecitationmetadata)tfdscoreDatasetInfo_DESCRIPTIONr   FeaturesDictAudioTexttfint64string_URL	_CITATIONMetadataDict)self r,   V/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/audio/libritts.py_infoL   s$   	zLibritts._infoc                 C   s   t | d }i }tjj|dG}tjd|d}|d}t	|D ].\}}|dkr,q#|
d d}	t|	dkrA|	d	 |	\}
}}}|||d
|t|
< q#W d    n1 s\w   Y  || jjd< d S )Nr   rbzr:gz)modefileobjzLibriTTS/speakers.tsvutf-8	    )gendersubsetnamespeakers)listvaluesr%   iogfileGFiletarfileopenextractfile	enumeratedecodestripsplitlenappendintinfor   )r+   archive_pathsarchive_pathspeaker_infoftarfspeakers_tsvnlinefieldsid_strr6   r7   r8   r,   r,   r-   _populate_metadata_   s&   

zLibritts._populate_metadatac                 C   s*   | t}| | dd | D }|S )Nc                 S   s$   g | ]\}}t jj|d |idqS )rK   )r8   
gen_kwargs)r   r   SplitGenerator).0kvr,   r,   r-   
<listcomp>z   s    z.Libritts._split_generators.<locals>.<listcomp>)download_DL_URLSrT   items)r+   
dl_managerarchivessplitsr,   r,   r-   _split_generatorsw   s   

zLibritts._split_generatorsc                 C   s:   t jjj}|||gB |tB | B d|t	? B S )zGenerates examples as dicts.merge_transcripts_and_audio)
r   r   lazy_importsapache_beamCreateFlatMap_extract_libritts_data	ReshuffleCombinePerKey_merge_dicts)r+   pipelinerK   beamr,   r,   r-   _build_pcollection   s   

zLibritts._build_pcollectionN)__name__
__module____qualname____doc__r   r   VersionVERSIONr.   rT   ra   rm   r,   r,   r,   r-   r   G   s    	r   c                 c   s`    | D ]*}| dd\}}}dd |ddd D \}}|||||d}||fV  qdS )	z4Generates partial examples from transcript CSV file.r2   r3   c                 S   s   g | ]}t |qS r,   )rH   )rW   elr,   r,   r-   rZ      s    z)_generate_transcripts.<locals>.<listcomp>_N   )r   r   r   r   r   )rC   rE   )transcript_csv_filerQ   keyr   r   r   r   exampler,   r,   r-   _generate_transcripts   s    rz   c                 c   s    t jjj| D ]<\}}|dr!t|D ]	\}}||fV  qq	|drEtt	j
t	j
|d }t| }d|i}||fV  q	dS )zFGenerate partial audio or transcript examples from a LibriTTS archive.z
.trans.tsvz.wavr   r   N)r   r   r[   	extractoriter_tarendswithrz   sixensure_textospathsplitextbasenamer<   BytesIOread)rK   r   contentsrx   ry   memfiler,   r,   r-   rg      s   


rg   c                 C   s   i }| D ]}| | q|S )N)update)dictsmergeddr,   r,   r-   rj      s   rj   )rq   
__future__r   r   r   r<   r   r?   r~   tensorflow.compat.v2compatv2r%   tensorflow_datasets.public_api
public_apir   r)   r!   r(   _DL_URLr\   r   BeamBasedBuilderr   rz   rg   rj   r,   r,   r,   r-   <module>   s4   C