
    љi                         S SK r S SKJrJr  SSKJr  SSKJr   S SKJ	r	  S SK
Jr  S SKJr  \ R                  " \5      r " S	 S
\5      rg! \ a    SrSr N*f = f)    N)DictList   )SpeechSynthesizer)TTSPreprocessor)SpeechGateway)UnifiedGateway)UnifiedTTSRequestc                      ^  \ rS rSrSSSSSSSSSSSSS.S	\S
\S\S\\\4   S\S\S\S\S\S\S\	\
   S\4U 4S jjjrS\4U 4S jjrSSSS.S\S
\S\	\   S\4S jjrS"S\S\S\S\4S  jjrS!rU =r$ )#SpeechGatewaySpeechSynthesizer   Nzhttp://127.0.0.1:8000/ttsFd      g      $@)service_namespeakerspeedstyle_mappertts_urlaudio_formatuse_local_gatewaymax_connectionsmax_keepalive_connectionstimeoutpreprocessorsdebugr   r   r   r   r   r   r   r   r   r   r   r   c          	         > [         TU ]  UUU	U
UUS9  Xl        X l        X0l        XPl        X`l        Xpl        U R                  (       a"  [        c  [        S5      e[        5       U l
        g S U l
        g )N)r   r   r   r   r   r   zbspeech_gateway is required for use_local_gateway=True. Install it with: pip install speech-gateway)super__init__r   r   r   r   r   r   r	   ImportErrorunified_gateway)selfr   r   r   r   r   r   r   r   r   r   r   r   	__class__s                Y/home/james-whalen/.local/lib/python3.13/site-packages/aiavatar/sts/tts/speech_gateway.pyr   'SpeechGatewaySpeechSynthesizer.__init__   s      	%+&?' 	 	
 )
(!2!!%!B  $2#3D #'D     returnc                    > [         TU ]  5       nU R                  US'   U R                  US'   U R                  US'   U R
                  US'   U R                  US'   U$ )Nr   r   r   r   r   )r   
get_configr   r   r   r   r   )r!   configr"   s     r#   r(   )SpeechGatewaySpeechSynthesizer.get_config:   s^    #%!%!2!2~ LLy**w LLy!%!2!2~r%   )r   	languagesdefaultnamer+   r,   c                    U R                   (       d  [        5       U l         U R                   R                  XUUS9  U(       a  Xl        X0l        g g )N)r+   default_speaker)r    r	   add_gatewayr   r   )r!   r-   gatewayr   r+   r,   s         r#   add_local_gateway0SpeechGatewaySpeechSynthesizer.add_local_gatewayC   sO     ###1#3D ((# 	) 	

  $"L r%   text
style_infolanguagec                   #    U(       a  UR                  5       (       d
  [        5       $ U R                  (       a  [        R	                  SU 35        U R                  XU5      I S h  vN nSU0nU R                  (       a  U R                  US'   U R                  (       a  U R                  US'   U R                  (       a  U R                  US'   U R                  U5      =n(       a-  XeS'   U R                  (       a  [        R	                  SU 35        U=(       d    0 R                  S0 5      R                  S5      =n(       a-  XuS'   U R                  (       a  [        R	                  S	U 35        U(       a(  US
:w  a"  [        R	                  SU 35        X5S'   US	 US	 U R                  (       aB  U R                  US'   U R                  (       a"  [        R	                  SU R                   35        U R                  (       a8  U R                  R                  [        S0 UD65      I S h  vN nUR                   $ U R"                  R%                  U R&                  US9I S h  vN nUR(                  $  GN NK N7f)NzSpeech synthesize: r4   r   r   r   stylezApply style: infozApply speed: zja-JPzApply language: r6   r   zApply audio format: )urljson )stripbytesr   loggerr9   
preprocessr   r   r   parse_stylegetr   r   r    ttsr
   
audio_datahttp_clientpostr   content)	r!   r4   r5   r6   processed_textrequest_jsonr8   r   resps	            r#   
synthesize)SpeechGatewaySpeechSynthesizer.synthesizeV   s    4::<<7N::KK-dV45  $tJJ /+/+<+<L(<<&*llL#::$(JJL! $$Z0050$)!zzmE734  %2**626::7CC5C$)!zzmE734 G+KK*8*56'/$^,Y' +/+<+<L(zz243D3D2EFG !!--11!1L1 D ??"))..LL! /  D <<_ KL
s7   A%I='I6(GI=-I9.7I=%I;&I=9I=;I=)r   r   r   r   r   r    r   )NN)__name__
__module____qualname____firstlineno__strfloatr   boolintr   r   r   dictr(   r2   r>   rK   __static_attributes____classcell__)r"   s   @r#   r   r      s&    !'+2 "'")+/3&( &( 	&(
 &( 38n&( &( &(  &( &( $'&( &( O,&( &( &(PD  ### 	#
 9# #&7 S 7 d 7 S 7 \a 7  7 r%   r   )loggingtypingr   r    r   preprocessorr   speech_gateway.gatewayr   speech_gateway.gateway.unifiedr	   r
   r   	getLoggerrM   r?   r   r<   r%   r#   <module>r_      s\       )4=8
 
		8	$| %6 |   Ns   A
 

AA