o
    *j'                     @   s   d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZ ddlmZ ddlmZ d	gZejejejd
G dd	 d	eZdS )    N)AnyDictListUnion)Preprocessors)Model)Fields
Frameworks   )Preprocessor)PREPROCESSORSWavToScp)module_namec                   @   s   e Zd ZdZdd Z					ddedededeeef d	e	d
e
eef fddZde
eef dededeeef d	e	de
eef d
e
eef fddZde
eef d
e
eef fddZde
eef d
e
eef fddZdS )r   z(generate audio scp from wave or ark
    c                 C   s   d S )N )selfr   r   ]/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/preprocessors/asr.py__init__   s   zWavToScp.__init__Nmodel
recog_typeaudio_formataudio_inaudio_fsreturnc                 C   sn   |d usJ d|d urt |dksJ d|d usJ d|d us&J d|| _| | j ||||}|S )Nzpreprocess model is emptyr   preprocess recog_type is empty preprocess audio_format is emptyzpreprocess audio_in is empty)lenam_modelforward)r   r   r   r   r   r   outr   r   r   __call__   s   
zWavToScp.__call__cmdc                 C   sP  t |dks
J dt |dksJ dt |d dks J dt |d dks,J dtj|d s8J dt |d	 dksDJ d
tj|d	 sPJ dt |d dks\J d|d	 |d	< |d |d< |d |d< ||d< ||d< |d |d< ||d< d|d v r|d d }nd }t|tr||d< |dkr| |}| |}|S )Nr   r   r   r   z#preprocess model[am_model] is emptyZam_model_pathz(preprocess model[am_model_path] is emptyz'preprocess am_model_path does not existmodel_workspacez*preprocess model[model_workspace] is emptyz)preprocess model_workspace does not existmodel_configz'preprocess model[model_config] is emptyr   r   r   	code_basewav_pathZfunasr)r   ospathexists
isinstancestrconfig_checkingenv_setting)r   r   r   r   r   r   r    r#   r   r   r   r   )   s`   





zWavToScp.forwardinputsc                 C   s  |d  dsJ d|d d |d< d|d v r |d d }nd}||d< d|d v r3|d d }nd}||d< d|d v rH|d d |d	< nd
|d	< |d tjkrd|d  ds_J d|d  drtj|d |d d }tj|s}J d||d< nd|d< |d  drtj|d |d d }tj|sJ d||d< nd}d|d< d|d v rtj|d |d d }tj|sJ dn|d }d|d v rtj|d |d d }nd}d|d v rtj|d |d d }nd}|r|rtj|rtj|r||d< ||d< nd|d< d|d< d|v r>|d dks5|d dkr:||d< n||d< |d  drbtj|d |d d }	tj|	s^J d|	|d< |S |d tjkr|d  dsxJ dtj|d |d d }
tj|
sJ d|
|d< |d  d sJ d!tj|d |d d  }tj|sJ d"||d < |S td#)$zconfig checking
        r"   typezmodel type does not existZ
model_typer#   Nmodelang
model_langzh-cnZ
batch_sizezbatch_size does not existam_model_configr!   zam_model_config does not exist asr_model_configzasr_model_config does not existasr_model_wav_configz#asr_model_wav_config does not existZlm_model_namelm_model_configlm_model_pathr   wavZpcmmvn_filezmvn_file does not exist
vocab_filezvocab_file does not existzvocab file does not existam_mvn_filezam_mvn_file does not existzam mvn file does not existzmodel type is mismatched)	__contains__r	   Ztorchr%   r&   joinr'   tf
ValueError)r   r,   r#   r.   r2   r4   r5   r7   r6   r9   r:   r;   r   r   r   r*   P   s   













zWavToScp.config_checkingc                 C   sv  |d dkr|d |d< |d dkr9t j|d d|d |d< t j|d dd|d< t j|d s8J d	nl|d d
krdt j|d |d |d< t j|d d|d< t j|d scJ d	nA|d dkrt j|d |d |d< t j|d d|d< t j|d sJ d	t j|d d|d< t j|d sJ dd|d v r|d d |d< |S d|d< |S )Nr   r8   r$   Zdatasets_pathr   Z
transcriptz	data.textZreference_textzreference text does not existZ	kaldi_arkZtfrecordzdata.txtzdata.idxZidx_textzidx text does not existr/   r"   r0   r1   )r%   r&   r=   r'   )r   r,   r   r   r   r+      sf   
zWavToScp.env_setting)NNNNN)__name__
__module____qualname____doc__r   r   r)   r   bytesintr   r   r   r   r*   r+   r   r   r   r   r      sD    






"'&q)r%   typingr   r   r   r   Zmodelscope.metainfor   Zmodelscope.models.baser   Zmodelscope.utils.constantr   r	   baser   builderr   __all__Zregister_moduleZaudioZ
wav_to_scpr   r   r   r   r   <module>   s   