
    Xi              	          d 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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j0                     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)Any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        j
                  t              ||d      4 d{   }t        j                  |j                          d{         }ddd      d{    D ]*  }d|vri |d<   d|d   vrg |d   d<   d|d   vs#g |d   d<   , |S 7 p7 K7 9# 1 d{  7  sw Y   IxY 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   headers_with_muidr	   jsonloadstext)r   r   r   urldatavoices         Y/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/edge_tts/voices.py__list_voicesr$      s      {{,l3#:#:#<"=
12	4%%m4   7 7 
**388:%567 7  9U" "E*eJ&7757E*12uZ'8868E*239 K)7 &67 7 7 7s`   AC"CC"#C=C	
>CC"C(C";C"	CC"CCCC")	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_voicesr2   8   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__Z   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)r4   r2   splitr6   r7   )clsr;   r8   r6   r"   s        r#   createzVoicesManager.create^   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())r7   RuntimeErrorr6   items)r8   rC   r"   matching_voicess       r#   findzVoicesManager.findm   s]     !!K 
  ${{
flln.ME
 
 
s   &AA)r   N)N)__name__
__module____qualname____doc__r9   classmethodr   r   r   rB   r   r   r   rH    r:   r#   r4   r4   U   s[    ) 48$T%[1	 V$56 4@R;S r:   r4   )rL   r   r   typingr   r   r   r,   r*   typing_extensionsr   	constantsr   r	   r
   drmr   r   r   r   r-   
SSLContextstrr$   BaseConnectorr2   r4   rN   r:   r#   <module>rV      s   ,  
 & &   $ D D  @ @$""$-0^^$DLSM$	%[$P 59QU7001AI#	%[:$ $r:   