o
    Si                     @   s   d dl mZ d dlmZmZmZ d dlmZmZm	Z	m
Z
mZ d dlmZmZ d dlmZ d dlmZ ede	eeeZdd	ed
ee defddZ	dd	eee	eeef dededee ddf
ddZdS )    )Path)OptionalTypeVarUnion)AudioSourceFeatures	Recordingcompute_num_samplesfastcopy)ArrayTemporalArray)Cut)PathlikeManifestNmanifestcutreturnc              	   C   s   t | tr+t| td| jddgd |d ur|jn| j|d ur&t|j| jdS | jdS t | t	r8t| ddddS t | t
rOt| d|d urG|jn| jddddS t | trbt| dt| jdddddS td	t|  )
Nshar )typechannelssource)sources
transformsdurationnum_samples)storage_typestorage_pathstorage_keyr   )startr   r   r   r   )r   arrayzUnexpected manifest type: )
isinstancer   r
   r   channel_idsr   r	   sampling_rater   r   r   r   r    RuntimeErrorr   )r   r    r%   E/home/ubuntu/.local/lib/python3.10/site-packages/lhotse/shar/utils.pyto_shar_placeholder   sF   



r'   datatarpathfieldc                 C   s"  t | tr|d usJ dt| |} t| |||d t|}t | tr<t| jdks.J dd| jd _|| jd _	d S t | t
tfra|| _|jdkrPd| _d S |jd	krZd
| _d S td| t | tr|| j_|jdkrud| j_d S |jd	krd
| j_d S td| tdt| j )NzK'field' argument must be provided when filling a Shar placeholder in a Cut.)r   r*   r(   r)      zIWe expected a single (possibly multi-channel) AudioSource in Shar format.memoryr   z.llcmemory_lilcomz.npy
memory_npyzUnknown array/tensor format: zUnknown manifest type: )r!   r   getattrfill_shar_placeholderr   r   lenr   r   r   r   r   r   suffixr   r$   r   r    __name__)r   r(   r)   r*   r%   r%   r&   r0   5   s<   










r0   )N)pathlibr   typingr   r   r   lhotser   r   r   r	   r
   lhotse.arrayr   r   
lhotse.cutr   lhotse.utilsr   r   r'   bytesstrr0   r%   r%   r%   r&   <module>   s(    -