/usr/local/lib/python3.6/site-packages/datasets/features/__pycache__
NameSizeModeActions
audio.cpython-36.pyc114730644editdlrm
features.cpython-36.pyc659380644editdlrm
image.cpython-36.pyc106000644editdlrm
translation.cpython-36.pyc51690644editdlrm
__init__.cpython-36.pyc5970644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/datasets/features/__pycache__/audio.cpython-36.pyc (11473B)
3 <%Eg5@sddlZddlmZmZddlmZddlmZmZm Z m Z m Z m Z ddl ZddlZddlmZddlmZddlmZdd lmZdd lmZmZerd d lmZeGd ddZdS)N) dataclassfield)BytesIO) TYPE_CHECKINGAnyClassVarDictOptionalUnion)version)config)xopen) array_cast)no_op_if_value_is_nullstring_to_dict) FeatureTypec @sNeZdZUdZdZeedZedZ e dZ ee  dZ e e  ejejejdZe eeddddZe dd Zee efed d d Zd!eeee ee edffed ddZedee dffdddZeejejfejdddZd"ejeejdddZ d#eee ee edffdddZ!d$ddZ"dd Z#dS)%AudioaAudio Feature to extract audio data from an audio file. Input: The Audio feature accepts as input: - A :obj:`str`: Absolute path to the audio file (i.e. random access is allowed). - A :obj:`dict` with the keys: - path: String with relative path of the audio file to the archive file. - bytes: Bytes content of the audio file. This is useful for archived files with sequential access. - A :obj:`dict` with the keys: - path: String with relative path of the audio file to the archive file. - array: Array containing the audio sample - sampling_rate: Integer corresponding to the samping rate of the audio sample. This is useful for archived files with sequential access. Args: sampling_rate (:obj:`int`, optional): Target sampling rate. If `None`, the native sampling rate is used. mono (:obj:`bool`, default ``True``): Whether to convert the audio signal to mono by averaging samples across channels. decode (:obj:`bool`, default ``True``): Whether to decode the audio data. If `False`, returns the underlying dictionary in the format {"path": audio_path, "bytes": audio_bytes}. Example: ```py >>> from datasets import load_dataset, Audio >>> ds = load_dataset("PolyAI/minds14", name="en-US", split="train") >>> ds = ds.cast_column("audio", Audio(sampling_rate=16000)) >>> ds[0]["audio"] {'array': array([ 2.3443763e-05, 2.1729663e-04, 2.2145823e-04, ..., 3.8356509e-05, -7.3497440e-06, -2.1754686e-05], dtype=float32), 'path': '/root/.cache/huggingface/datasets/downloads/extracted/f14948e0e84be638dd7943ac36518a4cf3324e8b7aa331c5ab11541518e9368c/en-US~JOINT_ACCOUNT/602ba55abb1e6d0fbce92065.wav', 'sampling_rate': 16000} ``` NTdict)bytespathF)defaultinitreprcCs|jS)N)pa_type)selfrA/usr/local/lib/python3.6/site-packages/datasets/features/audio.py__call__GszAudio.__call__)valuereturncCsy ddl}Wn,tk r8}ztd|WYdd}~XnXt|trNd|dSd|krt}|j||d|ddd|jddS|jd dk otj j |d rV|d j d rD|jddkrt d |jd rt j|d t jd jt jd}n t j|d dddjt jd}tt}|j|||ddd|jddSd|jd dSnF|jd dk sv|jd dk r|jd |jd dStd|ddS)zEncode example into a format for Arrow. Args: value (:obj:`str` or :obj:`dict`): Data passed as input to Audio feature. Returns: :obj:`dict` rNz;To support encoding audio data, please install 'soundfile'.)rrarray sampling_rateZwav)formatrZpcmzBTo use PCM files, please specify a 'sampling_rate' in Audio objectr)dtypeihr)r%modezUAn audio sample should have one of 'path' or 'bytes' but they are missing or None in .) soundfile ImportError isinstancestrrwritegetvaluegetosrisfileendswithKeyErrornpZ frombufferZint16ZastypeZfloat32Zmemmapr ValueError)rr sferrbufferZ bytes_valuerrrencode_exampleJs2      "   zAudio.encode_example)r token_per_repo_idr!cCs|jstd|ddk r.|dt|dfn |ddf\}}|dkr`|dkr`td|dn|dk r|jdr|j|r~|n|\}}nd|dk r|jdr|r|j|d\}}q|j|d|d \}}n&|r|j|\}}n|j||d \}}|||d S) aDecode example audio file into audio data. Args: value (:obj:`dict`): a dictionary with keys: - path: String with relative audio file path. - bytes: Bytes of the audio file. token_per_repo_id (:obj:`dict`, optional): To access and decode audio files from private repositories on the Hub, you can pass a dictionary repo_id (str) -> token (bool or str) Returns: dict zMDecoding is disabled for this feature. Please use Audio(decode=True) instead.rNrzJAn audio sample should have one of 'path' or 'bytes' but both are None in r)mp3opus)r;)rr"r#)decode RuntimeErrorrr6r3 _decode_mp3_decode_non_mp3_file_like_decode_non_mp3_path_like)rr r;rfiler"r#rrrdecode_examplexs 0zAudio.decode_exampler)r!cCs,ddlm}|jrtd|d|ddS)z[If in the decodable state, raise an error, otherwise flatten the feature into a dictionary.r)Valuez'Cannot flatten a decoded Audio feature.binarystring)rr)featuresrEr>r6)rrErrrflattens  z Audio.flatten)storager!cCs(tjj|jrJtjdgt|tjd}tjj||gddg|j d}ntjj |jr~|jj dr~tjdd|j D}ntjj |jr|jj dd kr|jd}ntjdgt|tjd}|jj dd kr|jd}ntjdgt|tjd}tjj||gddg|j d}t||jS) aCast an Arrow array to the Audio arrow storage type. The Arrow types that can be converted to the Audio pyarrow storage type are: - pa.string() - it must contain the "path" data - pa.struct({"bytes": pa.binary()}) - pa.struct({"path": pa.string()}) - pa.struct({"bytes": pa.binary(), "path": pa.string()}) - order doesn't matter Args: storage (Union[pa.StringArray, pa.StructArray]): PyArrow array to cast. Returns: pa.StructArray: Array in the Audio arrow storage type, that is pa.struct({"bytes": pa.binary(), "path": pa.string()}) N)typerr)maskr"cSs$g|]}|dk rtj|ndqS)N)rr:).0xrrr sz&Audio.cast_storage..r)patypes is_stringrKr"lenrF StructArray from_arraysis_nullZ is_structZget_all_field_indices to_pylistZget_field_indexrrGrr)rrJ bytes_array path_arrayrrr cast_storages   zAudio.cast_storage)rJ drop_pathsr!cstddtjfdd|jDtjd}|rPtjdgt|tjdn|jd}tjj ||gddg|j d }t ||j S) avEmbed audio files into the Arrow array. Args: storage (pa.StructArray): PyArrow array to embed. drop_paths (bool, default ``True``): If True, the paths are set to None. Returns: pa.StructArray: Array in the Audio arrow storage type, that is pa.struct({"bytes": pa.binary(), "path": pa.string()}) c Ss"t|d}|j}WdQRX|S)Nrb)rread)rfbytes_rrr path_to_bytess z*Audio.embed_storage..path_to_bytescs8g|]0}|dk r0|ddkr(|dq2|dndqS)Nrrr)rMrN)r`rrrOsz'Audio.embed_storage..)rKNrr)rL) rrPr"rWrFrSrGrrTrUrVrr)rrJr[rXrYr)r`r embed_storages    *zAudio.embed_storage)r;c "Csy ddl}Wn,tk r8}ztd|WYdd}~XnX|p@i}|dkrpddl}tj|jtjdkrptd |jdd}yt|t j d }||} Wnt t fk rd} YnXt |d | d } |j| |j|jd \} } WdQRX| | fS)Nrz:To support decoding audio files, please install 'librosa'.r=z1.0.30z4Decoding .opus files requires 'libsndfile'>=1.0.30, zPit can be installed via conda: `conda install -c conda-forge libsndfile>=1.0.30`z::rrepo_idr\)use_auth_token)srmonozDecoding .opus files requires 'libsndfile'>=1.0.30, it can be installed via conda: `conda install -c conda-forge libsndfile>=1.0.30`)librosar+r*r parse__libsndfile_version__r?splitrr ZHUB_DATASETS_URLr6r4rloadr#re) rrr$r;rgr8r* source_urlrbrcr^r"r#rrrrBs(   "zAudio._decode_non_mp3_path_likecCsyddl}ddl}Wn,tk r@}ztd|WYdd}~XnX|dkrhtj|jtjdkrhtd |j|\}}|j}|j r|j |}|j r|j |kr|j |||j dd}|j }||fS) NrzJTo support decoding audio files, please install 'librosa' and 'soundfile'.r=z1.0.30z4Decoding .opus files requires 'libsndfile'>=1.0.30, zPit can be installed via conda: `conda install -c conda-forge libsndfile>=1.0.30`Z kaiser_best)Zres_typezDecoding .opus files requires 'libsndfile'>=1.0.30, it can be installed via conda: `conda install -c conda-forge libsndfile>=1.0.30`) rgr*r+r rhrir?r]TreZto_monor#Zresample)rrCr$rgr7r8r"r#rrrrAs$  zAudio._decode_non_mp3_file_likec Csyddl}ddlj}Wn,tk rB}ztd|WYdd}~XnXy|jdWn,tk r~}ztd|WYdd}~XnX|j|dd\}}|jr|j|krt|d s|j j |kr|j ||j|_ |j |}|j}|j }|j r|jdd}||fS) NrzCTo support decoding 'mp3' audio files, please install 'torchaudio'.Zsox_iozidr-r%rrPstructrFrGrrr_typerr rr:rrDrIZ StringArrayrTrZrarBrAr@rrrrrs$ (    /% !& r)r1Z dataclassesrriortypingrrrrr r rqr5ZpyarrowrP packagingr r Z#download.streaming_download_managerrtablerZutils.py_utilsrrrHrrrrrrs