o
    Nig+                     @   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	m
  mZ ddlmZ G dd dejjZdd	 ZG d
d dejjZdd Zdd Zdd Zdd ZdS )$TED-LIUM speech recognition dataset.    )absolute_import)division)print_functionNc                       s(   e Zd ZdZejj fddZ  ZS )TedliumReleaseConfigz4BuilderConfig for a release of the TED-LIUM dataset.c                    s>   t t| jddtjdi| || _|| _|| _|| _	d S )Nversionz1.0.1 )
superr   __init__tfdscoreVersionurldownload_urlsplit_pathscitation)selfr   r   r   r   kwargs	__class__r   U/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/audio/tedlium.pyr
   #   s   

zTedliumReleaseConfig.__init__)	__name__
__module____qualname____doc__r   r   disallow_positional_argsr
   __classcell__r   r   r   r   r       s    r   c                  C   s  t dddddtjjtjddftjjtjddftjjtjdd	fgd
} t dddddtjjtjddftjjtjddftjjtjdd	fgd
}t ddddtj	j
dtj	jjdtjjtjdddftjjtjddd	ftjjtjddfgd
}| ||gS )zCCreates builder configs for all supported Tedlium dataset releases.release1aB          The TED-LIUM corpus is English-language TED talks, with transcriptions,
        sampled at 16kHz. It contains about 118 hours of speech.

        This is the TED-LIUM corpus release 1,
        licensed under Creative Commons BY-NC-ND 3.0
        (http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en).
        ab          @inproceedings{rousseau2012tedlium,
          title={TED-LIUM: an Automatic Speech Recognition dedicated corpus},
          author={Rousseau, Anthony and Del{\'e}glise, Paul and Est{\`e}ve, Yannick},
          booktitle={Conference on Language Resources and Evaluation (LREC)},
          pages={125--129},
          year={2012}
        }
        zhttps://www.openslr.org/7/z:http://www.openslr.org/resources/7/TEDLIUM_release1.tar.gzTEDLIUM_release1traindevtest)namedescriptionr   r   r   r   release2a          This is the TED-LIUM corpus release 2,
        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).

        Contains 1495 talks and transcripts.
        aj          @inproceedings{rousseau2014tedlium2,
          title={Enhancing the {TED-LIUM} Corpus with Selected Data for Language Modeling and More {TED} Talks},
          author={Rousseau, Anthony and Del{\'e}glise, Paul and Est{\`e}ve, Yannick},
          booktitle={Conference on Language Resources and Evaluation (LREC)},
          year={2014}
        }
        zhttps://www.openslr.org/19/z;http://www.openslr.org/resources/19/TEDLIUM_release2.tar.gzTEDLIUM_release2release3a          This is the TED-LIUM corpus release 3, licensed under Creative Commons
        BY-NC-ND 3.0.

        All talks and text are property of TED Conferences LLC.

        This new TED-LIUM release was made through a collaboration between the
        Ubiqus company and the LIUM (University of Le Mans, France)

        Contents:

        - 2351 audio talks in NIST sphere format (SPH), including talks from
          TED-LIUM 2: be careful, same talks but not same audio files (only
          these audio file must be used with the TED-LIUM 3 STM files)
        - 452 hours of audio
        - 2351 aligned automatic transcripts in STM format
        - TEDLIUM 2 dev and test data: 19 TED talks in SPH format with
          corresponding manual transcriptions (cf. 'legacy' distribution below).
        - Dictionary with pronunciations (159848 entries), same file as the one
          included in TED-LIUM 2
        - Selected monolingual data for language modeling from WMT12 publicly
          available corpora: these files come from the TED-LIUM 2 release, but
          have been modified to get a tokenization more relevant for English
          language

        Two corpus distributions:
        - the legacy one, on which the dev and test datasets are the same as in
          TED-LIUM 2 (and TED-LIUM 1).
        - the 'speaker adaptation' one, especially designed for experiments on
          speaker adaptation.
        a          @inproceedings{hernandez2018tedlium3,
          title={TED-LIUM 3: twice as much data and corpus repartition for experiments on speaker adaptation},
          author={Hernandez, Fran{\c{c}}ois and Nguyen, Vincent and Ghannay, Sahar and Tomashenko, Natalia and Est{\`e}ve, Yannick},
          booktitle={International Conference on Speech and Computer},
          pages={198--208},
          year={2018},
          organization={Springer}
        }
        zhttps://www.openslr.org/51/z9http://www.openslr.org/resources/51/TEDLIUM_release-3.tgz)r   extract_methodzTEDLIUM_release-3legacydata)r   r   SplitTRAINospathjoin
VALIDATIONTESTdownloadResourceExtractMethod
TAR_STREAM)r   r$   r&   r   r   r   _make_builder_configs/   sb   	!

=r5   c                   @   s.   e Zd ZdZe Zdd Zdd Zdd ZdS )	Tedliumr   c                 C   sf   t jj| | jjt jt jjddt j t	j
t jjg ddt	j
dd| jj| jjt jjdddS )Ni>  )sample_rate)unknownfemalemale)namesspeechtext
speaker_idgenderid)r=   r>   )builderr#   featuressupervised_keyshomepager   metadata)r   r   DatasetInfobuilder_configr#   rC   FeaturesDictAudioTexttfstring
ClassLabelr   r   MetadataDict)r   r   r   r   _info   s   zTedlium._infoc                 C   sP   | | jj}g }| jjD ]\}}dtj||i}|tj	j
||d q|S )N	directory)r"   
gen_kwargs)download_and_extractrH   r   r   r,   r-   r.   appendr   r   SplitGenerator)r   
dl_managerextracted_dirsplitssplitr-   r   r   r   r   _split_generators   s   zTedlium._split_generatorsc                 C   s<   t jjj}tjjtj	
|dd}|||B |tB S )Nstmz*stm)r   r   lazy_importsapache_beamrL   iogfileglobr,   r-   r.   CreateFlatMap _generate_examples_from_stm_file)r   pipelinerQ   beam	stm_filesr   r   r   _build_pcollection   s   
zTedlium._build_pcollectionN)	r   r   r   r   r5   BUILDER_CONFIGSrP   rZ   rg   r   r   r   r   r6      s    	r6   c              	   c   s    t j| }t jt j|d}tjj| Q}|D ]E}| }|	dd\}}}}}	}
}t
|}d| }tt j||t|t|t|	}d|||	|
g}|||t|
|d}||fV  qW d   dS 1 smw   Y  dS )z+Generate examples from a TED-LIUM stm file.sph    z%s.sph-r<   N)r,   r-   dirnamer.   rL   r^   r_   GFilestriprY   _maybe_trim_suffix_extract_audio_segmentintfloat_parse_gender)stm_pathstm_dirsph_dirflinefnchannelspeakerstartendlabel
transcript
audio_filesampleskeyexampler   r   r   rc      s.   "rc   c                 C   sB   |  dd}|d } t|dkr|d }|ds| d| 7 } | S )Nrj      r   ()rsplitlen
startswith)r   rX   suffixr   r   r   rp      s   
rp   c                 C   sT   t d| d dd }|sd}|S |dkrd}|S |dkr"d}|S |dkr(d}|S )	z-Parse gender string from STM "<label>" field.z,|_r   Nz<NAFr9   Mr:   )rerY   )	label_strr@   r   r   r   rt      s   rt   c           	      C   s   t jj| d}tjjjjj	|dd}W d   n1 sw   Y  |j
dks*J |dks0J t|d }t|d }||| }t| }|S )zFExtracts segment of audio samples (as an ndarray) from the given path.rb
nistsphere)formatNr   i  )rL   r^   r_   rn   r   r   r\   pydubAudioSegment	from_filechannelsrr   nparrayget_array_of_samples)	sph_pathr{   	start_secend_secrx   segmentstart_msend_msr   r   r   r   rq     s   rq   )r   
__future__r   r   r   r,   r   numpyr   tensorflow.compat.v2compatv2rL   tensorflow_datasets.public_api
public_apir   r   BuilderConfigr   r5   BeamBasedBuilderr6   rc   rp   rt   rq   r   r   r   r   <module>   s    ~,