
    Xi[                         d Z ddlZddlZddlZddlmZm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 dd	lmZ d
ee   ddfdZdeddfdZddZddZedk(  r e        yy)zJUtility functions for the command line interface. Used by the main module.    N)OptionalTextIO)tabulate   )CommunicateSubMakerlist_voices)DEFAULT_VOICE)UtilArgs)__version__proxyreturnc           
        K   t        |        d{   }t        |d       }g d}|D cg c]8  }|d   |d   dj                  |d	   d
         dj                  |d	   d         g: }}t        t	        ||             y7 oc c}w w)zPrint all available voices.r   Nc                     | d   S )N	ShortName )voices    W/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/edge_tts/util.py<lambda>z_print_voices.<locals>.<lambda>   s    eK.@     )key)NameGenderContentCategoriesVoicePersonalitiesr   r   z, VoiceTagr   r   )r	   sortedjoinprintr   )r   voicesheadersr   tables        r   _print_voicesr$      s     U++FF @AFKG   +(OIIeJ'(;<=IIeJ'(<=>		
E  
(5'
"# ,s    B	BB	=B*B	B	argsc                 h  K   	 t         j                  j                         rOt         j                  j                         r1| j                  s%t        dt         j                         t                t        | j                  | j                  | j                  | j                  | j                  | j                        }t!               }	 | j                  %| j                  dk7  rt#        | j                  d      nt         j                  j$                  }| j&                  '| j&                  dk7  rt#        | j&                  dd	
      nd}|| j&                  dk(  rt         j                  }|j)                         2 3 d{   }|d   dk(  r|j+                  |d          &|d   dv s.|j-                  |       @# t        $ r t        dt         j                         Y yw xY w7 e6 ||j+                  |j/                                |t         j                  j$                  ur|j1                          |$|t         j                  ur|j1                          yyy# t         j                  j$                  ur|j1                          $|t         j                  ur|j1                          w w w xY ww)z2Run TTS after parsing arguments from command line.zWarning: TTS output will be written to the terminal. Use --write-media to write to a file.
Press Ctrl+C to cancel the operation. Press Enter to continue.)filez
Operation canceled.N)ratevolumepitchr   -wbwutf-8encodingtypeaudiodata)WordBoundarySentenceBoundary)sysstdinisattystdoutwrite_mediar    stderrinputKeyboardInterruptr   textr   r(   r)   r*   r   r   openbufferwrite_subtitlesstreamwritefeedget_srtclose)r%   communicatesubmaker
audio_filesub_filechunks         r   _run_ttsrL   !   sD    99#**"3"3"5d>N>N+ ZZ G
 		

YY{{jjjjK zH +0@0@C0G !!4("" 	 ##/D4H4HC4O %%sW= 	
  4 4 ;zzH&--/ 	% 	%%V}'  v/v"FFe$?  %CJJ76	%/ NN8++-.SZZ...HCJJ$>NN %? SZZ...HCJJ$>NN %?so   J2A-F: 1AJ2	B1I :G&>G$?G&%I (I :$G!J2 G!!J2$G&&"I AJ2AJ//J2c                  .  K   t        j                  d      } | j                  d      }|j                  ddd       |j                  d	d
d       | j                  dddt         t               |j                  dddd       | j                  ddd       | j                  ddd       | j                  ddd       | j                  dd       | j                  dd        | j                  d!d"       | j                  d#d$d%t
         &       | j                  t               '      }|j                  r3t        |j                  (       d){    t        j                  d*       |j                  g|j                  d+v r$t        j                  j                         |_        n5t#        |j                  d,-      5 }|j                         |_        d)d)d)       |j                   t%        |       d){    y)y)7 # 1 sw Y   ,xY w7 w).zAsync main functionz9Text-to-speech using Microsoft Edge's online TTS service.)descriptionT)requiredz-tz--textzwhat TTS will say)helpz-fz--filez!same as --text but read from filez-vz--voicezvoice for TTS. Default: )rP   defaultz-lz--list-voicesz lists available voices and exits
store_true)rP   actionz--ratezset TTS rate. Default +0%%.z+0%z--volumezset TTS volume. Default +0%%.z--pitchzset TTS pitch. Default +0Hz.z+0Hzz--write-mediaz+send media output to file instead of stdoutz--write-subtitlesz7send subtitle output to provided file instead of stderrz--proxyz#use a proxy for TTS and voice list.z	--versionversionz	edge-tts )rS   rT   )	namespacer   Nr   )r+   z
/dev/stdinr.   r/   )argparseArgumentParseradd_mutually_exclusive_groupadd_argumentr
   r   
parse_argsr   r	   r$   r   r6   exitr'   r7   readr>   r?   rL   )parsergroupr%   r'   s       r   amainr_   X   s    $$OF ///>E	tX,?@	tX,OP
'7	   
/	   'DeT

)HRWX
	(FPVW
K   F   	(MN
I;-/H   xz2D$**---yy99++		(DIdii'2 (d IIK	( yytn  	.( ( 	s7   EHHA.HH"H>H?HHHc                  >    t        j                  t                      y)z$Run the main function using asyncio.N)asynciorunr_   r   r   r   mainrc      s    KKr   __main__)r   N)__doc__rV   ra   r6   typingr   r   r    r   r   r	   	constantsr
   data_classesr   rT   r   strr$   rL   r_   rc   __name__r   r   r   <module>rl      sp    P   
 #  0 0 $ "  $(3- $D $"4 4d 4n0f
 zF r   