o
    Si7                     @   s.  d 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	 ddl
mZmZmZ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mZ dZ	ddedee de	fddZdeddfdedee deeee f de dedeeeeeeef f f fddZ!d dededefddZ"dS )!u  
The following are the original TED-LIUM 2 README contents.

This is theTED-LIUM corpus release 2, English speech recognition training corpus from TED talks, created by Laboratoire d’Informatique de l’Université du Maine (LIUM) (mirrored here)
licensed under Creative Commons BY-NC-ND 3.0 (http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en).

All talks and text are property of TED Conferences LLC.

--- 

The TED-LIUM corpus was made from audio talks and their transcriptions available on the TED website. We have prepared and filtered these data in order to train acoustic models to participate to the International Workshop on Spoken Language Translation 2011 (the LIUM English/French SLT system reached the first rank in the SLT task). 

More details are given in this paper: 

A. Rousseau, P. Deléglise, and Y. Estève, "Enhancing the TED-LIUM Corpus with Selected Data for Language Modeling and More TED Talks",
in Proceedings of the Ninth International Conference on Language Resources and Evaluation (LREC’14), May 2014.


Please cite this reference if you use these data in your research work. 

--- 

Contents: 

- 1495 audio talks in NIST sphere format (SPH) 
- 1495 transcripts in STM format 
- Dictionary with pronunciation (159848 entries) 
- Selected monolingual data for language modeling from WMT12 publicly available corpora


SPH format info: 

Channels			: 1
Sample Rate		: 16000
Precision			: 16-bit
Bit Rate			: 256k
Sample Encoding	: 16-bit Signed Integer PCM

    N)ThreadPoolExecutor)partial)Path)DictOptionalSequenceUnion)RecordingSetSupervisionSegmentSupervisionSet$validate_recordings_and_supervisions)fix_manifests)normalize_text_tedlium)Pathlikeresumable_downloadsafe_extract)traindevtest.F
target_dirforce_downloadreturnc                 C   s   t | } | jddd | d }| d }|d }| r*td|j d| d |S td	||d
 tj|dd t	
|}t|| d W d    n1 sNw   Y  |  |S )NT)parentsexist_okzTEDLIUM_release2.tar.gzTEDLIUM_release2z
.completedz	Skipping z	 because z exists.z;http://www.openslr.org/resources/19/TEDLIUM_release2.tar.gz)filenamer   )ignore_errors)path)r   mkdiris_filelogginginfonamer   shutilrmtreetarfileopenr   touch)r   r   tar_path
corpus_dircompleted_detectortar r-   K/home/ubuntu/.local/lib/python3.10/site-packages/lhotse/recipes/tedlium2.pydownload_tedlium2>   s&   r/      nonetedlium_root
output_dirdataset_partsnum_jobsnormalize_textc              	   C   s  t | } |durt |nd}i }t|tr|gn|}t|}|D ]}td| d | | }tj|d d|d}	t|d 	d}
t
|
t
|	ksZJ d	t
|	 d
t
|
 dg }tt|d}|
D ]}|||| qdg }|D ]	}||  qtt|}t|	|\}	}|	|d||< tdi ||  |dur|	|d| d  ||d| d  q!W d   |S 1 sw   Y  |S )ae  
    Prepare manifests for the TED-LIUM v2 corpus.

    The manifests are created in a dict with three splits: train, dev and test.
    Each split contains a RecordingSet and SupervisionSet in a dict under keys 'recordings' and 'supervisions'.

    :param tedlium_root: Path to the unpacked TED-LIUM data.
    :param output_dir: Path where the manifests should be written.
    :param dataset_parts: Which parts of the dataset to prepare.
        By default, all parts are prepared.
    :param num_jobs: Number of parallel jobs to use.
    :return: A dict with standard corpus splits containing the manifests.
    NzProcessing z	 split...sphz*.sph)patternr5   stmz*.stmzMismatch: found z sphere files and z9 STM files. You might be missing some parts of TEDLIUM...)r6   )
recordingssupervisionstedlium2_recordings_z	.jsonl.gztedlium2_supervisions_r-   )r   
isinstancestrr   r!   r"   r	   from_dirlistgloblenr   _parse_stm_fileappendsubmitextendresultr   from_segmentsr   r   to_file)r2   r3   r4   r5   r6   corpusexsplitrootr:   stmsfutures_parse_stm_workerr9   segmentsfuturer;   r-   r-   r.   prepare_tedlium2U   sN   



""rT   r9   c                 C   s   g }|   Q}t|D ]C\}}| ^}}}}}	}}
t|t|	}}	d|
dd}|dkr1q|t| d| ||t|	| dddt	||d	|d
 qW d   |S 1 sZw   Y  |S )z+Helper function to parse a single STM file. z{NOISE}z[NOISE]ignore_time_segment_in_scoring-   )ndigitsr   English)idrecording_idstartdurationchanneltextlanguagespeakerN)
r'   	enumeraterM   floatjoinreplacerE   r
   roundr   )r9   r6   rR   fidxlrec_id_r]   endwordsr`   r-   r-   r.   rD      s2   

rD   )r   F)r1   )#__doc__r!   r$   r&   concurrent.futures.threadr   	functoolsr   pathlibr   typingr   r   r   r   lhotser	   r
   r   r   	lhotse.qar   lhotse.recipes.utilsr   lhotse.utilsr   r   r   TEDLIUM_PARTSboolr/   r?   intrT   rD   r-   r-   r-   r.   <module>   sN    (

?