
    Sܶi              	       &   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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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         R/root/projects/openclaw-proxy/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                   K   t          j        t          j                              }t	          j        | d          4 d{V }	 t          |||           d{V }nS# t          j        $ rA}|j        dk    r t          j
        |           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.
    )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II @ @ @ @ @ @ @W	@&w????????DD* 	@ 	@ 	@x3,Q///&w????????DDDDDD	@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ Ks<   CACB/.7B*%C*B//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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__Z   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>g   sL     
 
 
EJ@u@j%/"7"7"<"<Q"?@@
 
 
r:   T)r4   r2   r6   r7   )clsr;   r8   r6   s       r#   createzVoicesManager.create^   se       (5(={}}$$$$$$$=
 
NT
 
 
 "r:   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)rB   r"   rF   s     r#   rC   z&VoicesManager.find.<locals>.<listcomp>v   s:     
 
 
fllnn.M.ME.M.M.Mr:   )r7   RuntimeErrorr6   )r8   rF   matching_voicess    ` r#   findzVoicesManager.findm   sW     ! 	K  
 
 
 
#{
 
 
 r:   )r   N)N)__name__
__module____qualname____doc__r9   classmethodr   r   r   rE   r   r   r   rM   rI   r:   r#   r4   r4   U   s         ) ) ) ) 48 $T%[1	   [V$56 4@R;S      r:   r4   )rQ   r   r   typingr   r   r   r,   r*   typing_extensionsr   	constantsr   r	   r
   drmr   r   r   r   r-   
SSLContextstrr$   BaseConnectorr2   r4   rI   r:   r#   <module>rZ      su  , ,  



 & & & & & & & & & &   $ $ $ $ $ $ D D D D D D D D D D       @ @ @ @ @ @ @ @ @ @$"$-0^$DLSM$	%[$ $ $ $P 59QU  701AI#	%[   :$ $ $ $ $ $ $ $ $ $r:   