o
    SiP                      @   s   d Z ddl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	m
Z
mZ ddlmZmZ ddlmZ ddlmZ ddlmZmZmZmZ d	Z	
		ddedededefddZ	ddede
e de	ee	eeeef f f fddZdede	fddZdS )aX  
The Edinburgh International Accents of English Corpus

Citation

Sanabria, Ramon; Markl, Nina; Carmantini, Andrea; Klejch, Ondrej; Bell, Peter; Bogoychev, Nikolay. (2023). The Edinburgh International Accents of English Corpus, [dataset]. University of Edinburgh. School of Informatics. The Institute for Language, Cognition and Computation. The Centre for Speech Technology Research. https://doi.org/10.7488/ds/3832.

Description

English is the most widely spoken language in the world, used daily by millions of people as a first or second language in many different contexts.
As a result, there are many varieties of English.
Although the great many advances in English automatic speech recognition (ASR) over the past decades, results are usually reported based on test datasets which fail to represent the diversity of English as spoken today around the globe.
We present the first release of The Edinburgh International Accents of English Corpus (EdAcc).
This dataset attempts to better represent the wide diversity of English, encompassing almost 40 hours of dyadic video call conversations between friends.
Unlike other datasets, EdAcc includes a wide range of first and second-language varieties of English and a linguistic background profile of each speaker.
Results on latest public, and commercial models show that EdAcc highlights shortcomings of current English ASR models.
The best performing model, trained on 680 thousand hours of transcribed data, obtains an average of 19.7% WER -- in contrast to the the 2.7% WER obtained when evaluated on US English clean read speech.
Across all models, we observe a drop in performance on Jamaican, Indonesian, Nigerian, and Kenyan English speakers.
Recordings, linguistic backgrounds, data statement, and evaluation scripts are released on our website under CC-BY-SA.

Source: https://datashare.ed.ac.uk/handle/10283/4836
    N)Path)DictOptionalUnion)fix_manifests$validate_recordings_and_supervisions)RecordingSet)SupervisionSet)Pathlikeis_module_availableresumable_downloadsafe_extracti }  .F$https://datashare.ed.ac.uk/download/
target_dirforce_downloadbase_urlreturnc           
      C   s   d}t | } | d }| jddd |d }| r$td| d |S | | }t| d| ||d	 tj|dd
 t	|}|j
|d W d   n1 sQw   Y  d}t|| }	t|	| W d   n1 sow   Y  |  |S )ad  
    Download and extract the EDACC dataset.

    :param target_dir: Pathlike, the path of the dir to store the dataset.
    :param force_download: Bool, if True, download the data even if it exists.
    :param base_url: str, the url of the website used to fetch the archive from.
    :return: the path to downloaded and extracted directory with data.
    zDS_10283_8983.zipedaccTparentsexist_okz
.completedz Skipping EDACC download because z exists./)filenamer   )ignore_errors)pathNzedacc_v1.0.tar.gz)r   mkdiris_filelogginginfor   shutilrmtreezipfileZipFile
extractalltarfileopenr   touch)
r   r   r   archive_name
corpus_dircompleted_detectorarchive_pathziptar_nametar r/   H/home/ubuntu/.local/lib/python3.10/site-packages/lhotse/recipes/edacc.pydownload_edacc'   s0   r1   r)   
output_dirc              	   C   s>  ddl m} tdstdt| d } | d }|dur't|}|jddd	 i }t| d
 }t|d}|D ]}|j	dksEJ d| |j
tksLJ q7dd |D }dD ]}	| |	 }
t|
d }tdd |D }W d   n1 svw   Y  t|
d d}t| D ]\}}||v rt||d qW d   n1 sw   Y  ||
td\}}}t|
d }tttj|}W d   n1 sw   Y  |D ]}d|_|j|v |_||j  D ]
\}}t||| qqt||\}}t|| ||d||	< |dur||d|	 d  ||d|	 d  qV|S )aP  
    Returns the manifests which consist of the Recordings and Supervisions.

    :param corpus_dir: a path to the unzipped EDACC directory (has ``edacc_v1.0`` inside).
    :param output_dir: an optional path where to write the manifests.
    :return: a dict with structure ``{"dev|test": {"recordings|supervisions": <manifest>}}``
    r   )load_kaldi_data_dirpandasz/Please install pandas via 'pip install pandas'.z
edacc_v1.0dataNTr   zlinguistic_background.csvz*.wav   z$Unexpected multi-channel recording: c                 S   s(   i | ]}|j |j  d |jd j qS ) r   )idsourcessource).0rr/   r/   r0   
<dictcomp>r   s   ( z!prepare_edacc.<locals>.<dictcomp>)devtestsegmentsc                 s   s    | ]	}|  d  V  qdS )r6   N)split)r;   lr/   r/   r0   	<genexpr>y   s    z prepare_edacc.<locals>.<genexpr>zwav.scpw)file)sampling_ratez	conv.listEnglish)
recordingssupervisionsedacc_recordings_z	.jsonl.gzedacc_supervisions_)lhotse.kaldir3   r   
ValueErrorr   r   parse_linguistic_backgroundr   from_dirnum_channelsrF   _EDACC_SAMPLING_RATEr&   setsorteditemsprintmapstrstriplanguagerecording_idis_conversationalspeakersetattrr   r   to_file)r)   r2   r3   	audio_dir	manifestsspk2metarH   r<   wav_scprA   data_dirfsplit_rec_idsridrstrrI   _conv_rec_idsskeyvalr/   r/   r0   prepare_edaccS   s^   

rm   r   c              	      sr   dd l }|| }|jdddddddd	d
}d|j |d< d|j |d< dtfdd  fdd| D }|S )Nr   gender	ethnicity	educationaccentother_languages
birth_yearstart_english_year)zWhat is your gender?u!   What’s your ethnic background? z'What is your higher level of education?zIHow would you describe your accent in English? (e.g. Italian, Glaswegian)z^Do you speak any second languages? separate them with commas  (e.g., Mandarin,Catalan,French )u)   What’s your year of birth? (e.g., 1992)z6What year did you start learning English? (e.g., 1999))columnsi  ageyears_speaking_englishr   c                 S   sh   | dkrt |rd S t|S | dkr)t|trt |rg S dd |dD S t|tr2| S |S )Nrw   rr   c                 S   s   g | ]}|  qS r/   )rX   )r;   vr/   r/   r0   
<listcomp>   s    z>parse_linguistic_background.<locals>.parse.<locals>.<listcomp>,)mathisnanint
isinstancefloatrA   rW   rX   )rk   rl   r/   r/   r0   parse   s   

z*parse_linguistic_background.<locals>.parsec                    s*   i | ]\}  d   fdddD qS )PARTICIPANT_IDc                    s   i | ]
}| || qS r/   r/   )r;   m)r   rowr/   r0   r=      s    z:parse_linguistic_background.<locals>.<dictcomp>.<dictcomp>)rn   ro   rp   rq   rr   rv   rw   r/   )r;   rh   r   )r   r0   r=      s    z/parse_linguistic_background.<locals>.<dictcomp>)r4   read_csvrenamers   rt   r   iterrows)r   pddfra   r/   r   r0   rN      s&   

rN   )r   Fr   )N)__doc__r   r{   r    r%   r"   pathlibr   typingr   r   r   lhotser   r   lhotse.audior   lhotse.supervisionr	   lhotse.utilsr
   r   r   r   rQ   boolrW   r1   rm   rN   r/   r/   r/   r0   <module>   sD    
.
C