o
    5ôjõ  ã                   @   sL  d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZ d dl	Z	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 ddlmZmZ ddlmZ dd	lmZ d
ddddddddddddœZddddddddddd d dœZd!ed"ed#ed$eeef fd%d&„Zd$ee fd'd(„Z 			)d/d*ed+eeee	j!f  d,ed#ed$ef
d-d.„Z"dS )0é    N)ÚListÚOptionalÚUnion)Útqdmé   )Ú
load_audioÚlog_mel_spectrogramÚpad_or_trim)ÚDecodingOptionsÚDecodingResultÚdecodeÚdetect_language)ÚModelDimensionsÚWhisper)Ú
transcribe)Ú__version__z‚https://openaipublic.azureedge.net/main/whisper/models/d3dd57d32accea0b295c96e26691aa14d8822fac7d9d27d5dc00b4ca2826dd03/tiny.en.ptzhttps://openaipublic.azureedge.net/main/whisper/models/65147644a518d12f04e32d6f3b26facc3f8dd46e5390956a9424a650c0ce22b9/tiny.ptz‚https://openaipublic.azureedge.net/main/whisper/models/25a8566e1d0c1e2231d1c762132cd20e0f96a85d16145c3a00adf5d1ac670ead/base.en.ptzhttps://openaipublic.azureedge.net/main/whisper/models/ed3a0b6b1c0edf879ad9b11b1af5a0e6ab5db9205f891f668f8b0e6c6326e34e/base.ptzƒhttps://openaipublic.azureedge.net/main/whisper/models/f953ad0fd29cacd07d5a9eda5624af0f6bcf2258be67c92b79389873d91e0872/small.en.ptz€https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.ptz„https://openaipublic.azureedge.net/main/whisper/models/d7440d1dc186f76616474e0ff0b3b6b879abc9d1a4926b7adfa41db2d497ab4f/medium.en.ptz�https://openaipublic.azureedge.net/main/whisper/models/345ae4da62f9b3d59415adc60127b97c714f32e89e936602e85993674d08dcb1/medium.ptzƒhttps://openaipublic.azureedge.net/main/whisper/models/e4b87e7e0bf463eb8e6956e646f1e277e901512310def2c24bf0e11bd3c28e9a/large-v1.ptzƒhttps://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.ptzƒhttps://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt)ztiny.enZtinyzbase.enÚbasezsmall.enZsmallz	medium.enZmediumzlarge-v1zlarge-v2zlarge-v3Zlarges%   ABzY8J1N>@0{>%R00Bk>$p{7v037`oCl~+#00s#   ABzY8bu8Lr0{>%RKn9Fp%m@SkK7Kt=7ytkOs%   ABzY8;40c<0{>%RzzG;p*o+Vo09|#PsxSZm00s(   ABzY8KQ!870{>%RzyTQH3`Q^yNP!>##QT-<FaQ7ms4   ABzY8>?_)10{>%RpeA61k&I|OI3I$65C{;;pbCHh0B{qLQ;+}v00s1   ABzY8DmU6=0{>%Rpa?J`kvJ6qF(V^F86#Xh7JUGMK}P<N0000s>   ABzY8usPae0{>%R7<zz_OvQ{)4kMa0BMw6u5rT}kRKX;$NfYBv00*Hl@qhsU00s,   ABzY8B0Jh+0{>%R7}kK1fFL7w6%<-Pf*t^=N)Qr&0RR9s2   ABzY8r9j$a0{>%R7#4sLmoOs{s)o3~84-RPdcFk!JR<kSfC2yjsK   ABzY8zd+h!0{>%R7=D0pU<_bnWW*tkYAhobTNnu$jnkEkXqp)j;w1Tzk)UH3X%SZd&fFZ2fC2yjs9   ABzY8gWO1E0{>%R7(9S+Kn!D~%ngiGaR?*L!iJG9p-nab0JQ=-{D1-g00ÚurlÚrootÚ	in_memoryÚreturnc              
   C   sº  t j|dd� |  d¡d }t j |t j | ¡¡}t j |¡r,t j |¡s,t|› d�ƒ‚t j |¡rbt	|dƒ�}| 
¡ }W d   ƒ n1 sFw   Y  t |¡ ¡ |krZ|rX|S |S t |› d�¡ tj | ¡�S}t	|dƒ�>}tt| ¡  d	¡ƒd
dddd��}		 | 
d¡}
|
s‰n| |
¡ |	 t|
ƒ¡ q�W d   ƒ n1 s w   Y  W d   ƒ n1 s¯w   Y  W d   ƒ n1 s¾w   Y  t	|dƒ 
¡ }t |¡ ¡ |kr×tdƒ‚|rÛ|S |S )NT)Úexist_okú/éþÿÿÿz! exists and is not a regular fileÚrbzH exists, but the SHA256 checksum does not match; re-downloading the fileÚwbzContent-LengthéP   ZiBi   )ZtotalZncolsZunitZ
unit_scaleZunit_divisori    zeModel has been downloaded but the SHA256 checksum does not not match. Please retry loading the model.)ÚosÚmakedirsÚsplitÚpathÚjoinÚbasenameÚexistsÚisfileÚRuntimeErrorÚopenÚreadÚhashlibZsha256Z	hexdigestÚwarningsÚwarnÚurllibZrequestZurlopenr   ÚintÚinfoÚgetÚwriteÚupdateÚlen)r   r   r   Zexpected_sha256Zdownload_targetÚfZmodel_bytesÚsourceÚoutputZloopÚbuffer© r6   úc/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/whisper/__init__.pyÚ	_download2   sT   
ÿÿû

úö€ÿ€ ÿr8   c                   C   s   t t ¡ ƒS )z%Returns the names of available models)ÚlistÚ_MODELSÚkeysr6   r6   r6   r7   Úavailable_models^   s   r<   FÚnameÚdeviceÚdownload_rootc                 C   s:  |du rt j ¡ rdnd}|du r'tj tj d¡d¡}tj t d|¡d¡}| tv r8t	t|  ||ƒ}t
|  }ntj | ¡rL|rGt| dƒ ¡ n| }d}ntd	| › d
tƒ › �ƒ‚|r^t |¡nt|dƒ�}t j||d�}W d  ƒ n1 suw   Y  ~tdi |d ¤Ž}	t|	ƒ}
|
 |d ¡ |dur˜|
 |¡ |
 |¡S )ae  
    Load a Whisper ASR model

    Parameters
    ----------
    name : str
        one of the official model names listed by `whisper.available_models()`, or
        path to a model checkpoint containing the model dimensions and the model state_dict.
    device : Union[str, torch.device]
        the PyTorch device to put the model into
    download_root: str
        path to download the model files; by default, it uses "~/.cache/whisper"
    in_memory: bool
        whether to preload the model weights into host memory

    Returns
    -------
    model : Whisper
        The Whisper ASR model instance
    NÚcudaZcpuú~z.cacheZXDG_CACHE_HOMEÚwhisperr   zModel z not found; available models = )Zmap_locationÚdimsZmodel_state_dictr6   )Útorchr@   Zis_availabler   r    r!   Ú
expanduserÚgetenvr:   r8   Ú_ALIGNMENT_HEADSr$   r&   r'   r%   r<   ÚioÚBytesIOÚloadr   r   Zload_state_dictZset_alignment_headsZto)r=   r>   r?   r   ÚdefaultZcheckpoint_fileZalignment_headsÚfpZ
checkpointrC   Úmodelr6   r6   r7   Ú
load_modelc   s4   
ÿÿý

rN   )NNF)#r(   rH   r   r+   r)   Útypingr   r   r   rD   r   Zaudior   r   r	   Zdecodingr
   r   r   r   rM   r   r   r   Úversionr   r:   rG   ÚstrÚboolÚbytesr8   r<   r>   rN   r6   r6   r6   r7   Ú<module>   sn    ôô",üÿþýüû