
    i              	       b   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  ej         ej                    	          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dS )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)cafilesessionssl_ctxproxyreturnc                   K   |                      t           dt          j                     dt           t          j        t                    ||d          4 d{V 	 }t          j        |	                                 d{V           }ddd          d{V  n# 1 d{V swxY w Y   |D ]5}d|vri |d<   d|d         vrg |d         d<   d|d         vrg |d         d<   6|S )	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         V/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/edge_tts/voices.py__list_voicesr%      s       {{ 	4 	43#:#<#< 	4 	41	4 	4%m44    7 7 7 7 7 7 7 7 
*388::%5%5%5%5%5%5667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7  9 9U"" "E*eJ&77757E*12uZ'88868E*23Ks   -B
B'*B')	connectorr   r&   c                 v  K   t          j        | d          4 d{V }	 t          |t          |           d{V }nX# t           j        $ rF}|j        dk    r t          j        |           t          |t          |           d{V }Y d}~nd}~ww xY wddd          d{V  n# 1 d{V swxY w Y   |S )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.
    T)r&   	trust_envNi  )aiohttpClientSessionr%   _SSL_CTXClientResponseErrorstatusr   handle_client_response_error)r&   r   r   r"   es        r$   list_voicesr0   :   s       $yDIII A A A A A A AW	A&w%@@@@@@@@DD* 	A 	A 	Ax3,Q///&w%@@@@@@@@DDDDDD	AA A A A A A A A A A A A A A A A A A A A A A A A A A A Ks7   B(>B(B<B	B(BB((
B25B2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dS )VoicesManagerzF
    A class to find the correct voice based on their attributes.
    r   Nc                 "    g | _         d| _        d S )NF)voicescalled_create)selfs    r$   __init__zVoicesManager.__init__[   s    02#(    custom_voicesc                    K   t                      }|t                       d{V n|}d |D             |_        d|_        |S )z\
        Creates a VoicesManager object and populates it with all available voices.
        Nc                 \    g | ])}i |d |d                              d          d         i*S )LanguageLocale-r   )split).0r#   s     r$   
<listcomp>z(VoicesManager.create.<locals>.<listcomp>h   sL     
 
 
EJ@u@j%/"7"7"<"<Q"?@@
 
 
r8   T)r2   r0   r4   r5   )clsr9   r6   r4   s       r$   createzVoicesManager.create_   se       (5(={}}$$$$$$$=
 
NT
 
 
 "r8   kwargsc                 Z    | j         st          d          fd| j        D             }|S )zM
        Finds all matching voices based on the provided attributes.
        z9VoicesManager.find() called before VoicesManager.create()c                 h    g | ].}                                 |                                 k    ,|/S  )items)r@   r#   rD   s     r$   rA   z&VoicesManager.find.<locals>.<listcomp>w   s:     
 
 
fllnn.M.ME.M.M.Mr8   )r5   RuntimeErrorr4   )r6   rD   matching_voicess    ` r$   findzVoicesManager.findn   sW     ! 	K  
 
 
 
#{
 
 
 r8   )r   N)N)__name__
__module____qualname____doc__r7   classmethodr   r   r   rC   r   r   r   rK   rG   r8   r$   r2   r2   V   s         ) ) ) ) 48 $T%[1	   [V$56 4@R;S      r8   r2   )rO   r   r   typingr   r   r   r)   certifityping_extensionsr   	constantsr   r	   r
   drmr   r   r   r   create_default_contextwherer+   r*   
SSLContextstrr%   BaseConnectorr0   r2   rG   r8   r$   <module>r[      s  , ,  



 & & & & & & & & & &   $ $ $ $ $ $ D D D D D D D D D D       @ @ @ @ @ @ @ @ @ @%3%]W]__===$"$-0^$DLSM$	%[$ $ $ $P 59QU  701AI#	%[   8$ $ $ $ $ $ $ $ $ $r8   