U
    %d                     @   sP  d dl mZmZmZmZ d dlZd dlmZ d dlmZ	 e	
ddrTd dlZd dlZddd	d
dgZdeeeeeeef  dddZe	ddeeeeef  dddZe	ddeeeeef  dddZe	ddeeeeef  ddd	Ze	ddeeeeef  ddd
Ze	ddeeeeef  dddZdS )    )AnyCallableIterableTupleN)Tensor)module_utilskaldi_ionumpyread_vec_int_arkread_vec_flt_scpread_vec_flt_arkread_mat_scpread_mat_arkF)
file_or_fdfnconvert_contiguousreturnc                 c   s4   || D ]&\}}|rt |}|t|fV  qdS )a  Takes a method invokes it. The output is converted to a tensor.

    Args:
        file_or_fd (str/FileDescriptor): File name or file descriptor
        fn (Callable): Function that has the signature (file name/descriptor) and converts it to
            Iterable[Tuple[str, Tensor]].
        convert_contiguous (bool, optional): Determines whether the array should be converted into a
            contiguous layout. (Default: ``False``)

    Returns:
        Iterable[Tuple[str, Tensor]]: The string is the key and the tensor is vec/mat
    N)npZascontiguousarraytorchZ
from_numpy)r   r   r   keyZnp_arr r   7/tmp/pip-unpacked-wheel-lbdmvq91/torchaudio/kaldi_io.py _convert_method_output_to_tensor   s    
r   )r   r   c                 C   s   t | tjddS )a  Create generator of (key,vector<int>) tuples, which reads from the ark file/stream.

    Args:
        file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor

    Returns:
        Iterable[Tuple[str, Tensor]]: The string is the key and the tensor is the vector read from file

    Example
        >>> # read ark to a 'dictionary'
        >>> d = { u:d for u,d in torchaudio.kaldi_io.read_vec_int_ark(file) }
    T)r   )r   r   r
   r   r   r   r   r
   -   s    c                 C   s   t | tjS )a  Create generator of (key,vector<float32/float64>) tuples, read according to Kaldi scp.

    Args:
        file_or_fd (str/FileDescriptor): scp, gzipped scp, pipe or opened file descriptor

    Returns:
        Iterable[Tuple[str, Tensor]]: The string is the key and the tensor is the vector read from file

    Example
        >>> # read scp to a 'dictionary'
        >>> # d = { u:d for u,d in torchaudio.kaldi_io.read_vec_flt_scp(file) }
    )r   r   r   r   r   r   r   r   A   s    c                 C   s   t | tjS )a  Create generator of (key,vector<float32/float64>) tuples, which reads from the ark file/stream.

    Args:
        file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor

    Returns:
        Iterable[Tuple[str, Tensor]]: The string is the key and the tensor is the vector read from file

    Example
        >>> # read ark to a 'dictionary'
        >>> d = { u:d for u,d in torchaudio.kaldi_io.read_vec_flt_ark(file) }
    )r   r   r   r   r   r   r   r   R   s    c                 C   s   t | tjS )a  Create generator of (key,matrix<float32/float64>) tuples, read according to Kaldi scp.

    Args:
        file_or_fd (str/FileDescriptor): scp, gzipped scp, pipe or opened file descriptor

    Returns:
        Iterable[Tuple[str, Tensor]]: The string is the key and the tensor is the matrix read from file

    Example
        >>> # read scp to a 'dictionary'
        >>> d = { u:d for u,d in torchaudio.kaldi_io.read_mat_scp(file) }
    )r   r   r   r   r   r   r   r   c   s    c                 C   s   t | tjS )a  Create generator of (key,matrix<float32/float64>) tuples, which reads from the ark file/stream.

    Args:
        file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor

    Returns:
        Iterable[Tuple[str, Tensor]]: The string is the key and the tensor is the matrix read from file

    Example
        >>> # read ark to a 'dictionary'
        >>> d = { u:d for u,d in torchaudio.kaldi_io.read_mat_ark(file) }
    )r   r   r   r   r   r   r   r   t   s    )F)typingr   r   r   r   r   r   Ztorchaudio._internalr   Z
_mod_utilsZis_module_availabler   r	   r   __all__boolstrr   Zrequires_moduler
   r   r   r   r   r   r   r   r   <module>   s:   
   




