
    (HJj                        d dl mZ d dlmZmZmZ d dlmZ d dl	m
Z
 d dlZd dlmZmZmZ dZi dddddd	d
d
ddddddddddddddddddddddddZdej&                  dededej&                  fdZee   edej.                  fdeded ej0                  fd!Z	 	 d(d"eeef   d#ed$ed%ede
j6                  f
d&Z	 	 d(d"eeef   d#ed$ed%ede
j6                  f
d'Zy))    )Path)AnyOptionalUnionN)base_load_modelget_model_pathload_configi>  
cohere_asrfireredasr2glmglmasr
sensevoicevoxtralvoxtral_realtime	vibevoicevibevoice_asr	qwen3_asrfun_asr_nanocanary	moonshinemmsgranite_speechgranite_speech_narqwen2_audiomega_asraudioorig_sr	target_srreturnc                 &    ddl m}  || ||d      S )Nr   )resample_audioaxis)mlx_audio.utilsr!   )r   r   r   _resample_audios       ]/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/mlx_audio/stt/utils.pyr!   r!       s    A5'91==    Ffilesrdtypec                     ddl m}  || d      \  }}||k7  rt        |||      }t        j                  ||      j                  d      S )a?  
    Open an audio file and read as mono waveform, resampling as necessary

    Parameters
    ----------
    file: str
        The audio file to open

    sr: int
        The sample rate to resample the audio if necessary

    Returns
    -------
    A NumPy array containing the audio waveform, in float32 dtype.
    r   )readT)	always_2d)r*      r"   )mlx_audio.audio_ior,   r!   mxarraymean)r(   r)   
from_stdinr*   
audio_readr   sample_rates          r&   
load_audior6   &   sM    * 6#DD9E;buk2688E',,!,44r'   
model_pathlazystrictkwargsc           	      ,    t        d| dt        ||d|S )a  
    Load and initialize an STT model from a given path.

    Args:
        model_path: The path or HuggingFace repo to load the model from.
        lazy: If False, evaluate model parameters immediately.
        strict: If True, raise an error if any weights are missing.
        **kwargs: Additional keyword arguments (revision, force_download).

    Returns:
        nn.Module: The loaded and initialized model.
    stt)r7   categorymodel_remappingr8   r9    )r   MODEL_REMAPPINGr7   r8   r9   r:   s       r&   
load_modelrB   C   s/    $  '  r'   c                      t        | f||d|S )ac  
    Load a speech-to-text model from a local path or HuggingFace repository.

    This is the main entry point for loading STT models. It automatically
    detects the model type and initializes the appropriate model class.

    Args:
        model_path: The local path or HuggingFace repo ID to load from.
        lazy: If False, evaluate model parameters immediately.
        strict: If True, raise an error if any weights are missing.
        **kwargs: Additional keyword arguments such as `revision` and
            `force_download`.

    Returns:
        nn.Module: The loaded and initialized model.

    )r8   r9   )rB   rA   s       r&   loadrD   _   s    . jEtFEfEEr'   )FF)pathlibr   typingr   r   r   mlx.corecorer0   mlx.nnnnnumpynpr$   r   r   r	   SAMPLE_RATEr@   ndarrayintr!   strfloat32Dtyper6   boolModulerB   rD   r?   r'   r&   <module>rU      s    ' '    H H,= 
8 ,	
 y *   N h  
5 & . =  
!(>"** >s >s >rzz > jj	5
55 88	5> c4i 
  	
 YY< Fc4i F
F F 	F
 YYFr'   