
    ;3h              	          d Z ddlZddlZddlmZmZ ddlZddlZddlm	Z	 ddl
mZmZmZ ddlmZ ddlmZmZmZ d	ej&                  d
ej(                  dee   dee   fdZddddeej.                     dee   dee   fdZ G d d      Zy)z|This module contains functions to list all available voices and a class to find the
correct voice based on their attributes.    N)ListOptional)Unpack   )SEC_MS_GEC_VERSIONVOICE_HEADERS
VOICE_LIST)DRM)VoiceVoicesManagerFindVoicesManagerVoicesessionssl_ctxproxyreturnc                   K   | j                  t         dt        j                          dt         t
        ||d      4 d{   }t        j                  |j                          d{         }ddd      d{    D ]V  }|d   d   D cg c]  }|j                          c}|d   d<   |d   d   D cg c]  }|j                          c}|d   d<   X |S 7 7 w7 e# 1 d{  7  sw Y   uxY wc c}w c c}w w)	a  
    Private function that makes the request to the voice list URL and parses the
    JSON response. This function is used by list_voices() and makes it easier to
    handle client response errors related to clock skew.

    Args:
        session (aiohttp.ClientSession): The aiohttp session to use for the request.
        ssl_ctx (ssl.SSLContext): The SSL context to use for the request.
        proxy (Optional[str]): The proxy to use for the request.

    Returns:
        List[Voice]: A list of voices and their attributes.
    z&Sec-MS-GEC=z&Sec-MS-GEC-Version=T)headersr   sslraise_for_statusNVoiceTagContentCategoriesVoicePersonalities)
getr	   r
   generate_sec_ms_gecr   r   jsonloadstextstrip)r   r   r   urldatavoicecategorypersonalitys           O/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/edge_tts/voices.py__list_voicesr%      s+      {{,l3#:#:#<"=
12	4   9 9 
 JJSXXZ'789 9  
 "*-.AB2
 NN2
j-.  %Z01EF3
 3
j./
 K/9 (89 9 9 92
3
sr   ADC D#C&*C"
+C&3D>C$?DC;)D<D D"C&$D&C8,C/-C84D)	connectorr   r&   c                   K   t        j                  t        j                               }t	        j
                  | d      4 d{   }	 t        |||       d{   }ddd      d{    |S 7 ,7 # t        j                  $ rE}|j                  dk7  r t        j                  |       t        |||       d{  7  }Y d}~id}~ww xY w7 e# 1 d{  7  sw Y   S xY ww)a  
    List all available voices and their attributes.

    This pulls data from the URL used by Microsoft Edge to return a list of
    all available voices.

    Args:
        connector (Optional[aiohttp.BaseConnector]): The connector to use for the request.
        proxy (Optional[str]): The proxy to use for the request.

    Returns:
        List[Voice]: A list of voices and their attributes.
    )cafileT)r&   	trust_envNi  )r   create_default_contextcertifiwhereaiohttpClientSessionr%   ClientResponseErrorstatusr
   handle_client_response_error)r&   r   r   r   r    es         r$   list_voicesr3   ;   s       ((@G$$yDI @ @W	@&w??D@ @ K@?** 	@xx3,,Q/&w???D	@@ @ @ @ Ks   AC*A3C*
CA7A5A7!C*,C-C*5A77C
5C
?C C
C
CCC*C'CC'"C*c                   ^    e Zd ZdZd	dZe	 d
deee      dd fd       Z	de
e   dee   fdZy)VoicesManagerzF
    A class to find the correct voice based on their attributes.
    r   Nc                      g | _         d| _        y )NF)voicescalled_create)selfs    r$   __init__zVoicesManager.__init__]   s    02#(    custom_voicesc                    K   t               }|t                d{   n|}|D cg c]  }i |d|d   j                  d      d   i! c}|_        d|_        |S 7 ?c c}w w)z\
        Creates a VoicesManager object and populates it with all available voices.
        NLanguageLocale-r   T)r5   r3   splitr7   r8   )clsr<   r9   r7   r!   s        r$   createzVoicesManager.createa   st      (5(={}$$=NT
EJ@u@j%/"7"7"<Q"?@
 " %
s    A#A
A#$AA#A#kwargsc                     | j                   st        d      | j                  D cg c]&  }|j                         |j                         k  s%|( }}|S c c}w )zM
        Finds all matching voices based on the provided attributes.
        z9VoicesManager.find() called before VoicesManager.create())r8   RuntimeErrorr7   items)r9   rD   r!   matching_voicess       r$   findzVoicesManager.findp   s]     !!K 
  ${{
flln.ME
 
 
s   &AA)r   N)N)__name__
__module____qualname____doc__r:   classmethodr   r   r   rC   r   r   r   rI    r;   r$   r5   r5   X   s[    ) 48$T%[1	 V$56 4@R;S r;   r5   )rM   r   r   typingr   r   r-   r+   typing_extensionsr   	constantsr   r   r	   drmr
   r   r   r   r.   
SSLContextstrr%   BaseConnectorr3   r5   rO   r;   r$   <module>rW      s   ,  
 !   $ D D  @ @'""'-0^^'DLSM'	%['V 59QU7001AI#	%[:$ $r;   