
    ;3h                         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	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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    M/var/www/html/audio-gradio/venv/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                   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k(  s/|j-                  |       A# t        $ r t        dt         j                         Y yw xY w7 f6 | j.                  dkD  r|j1                  | j.                         ||j+                  |j3                                |t         j                  j$                  ur|j5                          |$|t         j                  ur|j5                          yyy# t         j                  j$                  ur|j5                          $|t         j                  ur|j5                          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WordBoundaryr   )sysstdinisattystdoutwrite_mediar   stderrinputKeyboardInterruptr   textr   r'   r(   r)   r   r   openbufferwrite_subtitlesstreamwritefeedwords_in_cue
merge_cuesget_srtclose)r$   communicatesubmaker
audio_filesub_filechunks         r   _run_ttsrL       se    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.0e$?  %CJJ76	%/ q  1 12NN8++-.SZZ...HCJJ$>NN %? SZZ...HCJJ$>NN %?sp   KA-F; 1AK	B1J :G'>G%?G'&J )J ;$G"K!G""K%G''AJ 3AKAKK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dt
                | j                  d!d"       | j                  d#d$       | j                  d%d&       | j                  t               '      }|j                  r3t        |j                  (       d){    t        j                  d*       |j                  h|j                  d+v r$t        j                  j                         |_        n6t#        |j                  d,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--words-in-cuez/number of words in a subtitle cue. Default: 10.
   )rP   rQ   r0   z--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.)	namespacer   Nr   )r*   z
/dev/stdinrr-   r.   )argparseArgumentParseradd_mutually_exclusive_groupadd_argumentr
   int
parse_argsr   r	   r#   r   r4   exitr&   r5   readr<   r=   rL   )parsergroupr$   r&   s       r   amainra   Z   s    $$OF ///>E	tX,?@	tX,OP
'7	   
/	   'DeT

)HRWX
	(FPVW
>	   K   F   	(MNxz2D$**---yy99++		(DIdiiw7 (4 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runra   r   r   r   mainre      s    KKr   __main__)r   N)__doc__rW   rc   r4   typingr   r   r    r   r   r	   	constantsr
   data_classesr   strr#   rL   ra   re   __name__r   r   r   <module>rn      sm    P   
 #  0 0 $ "$(3- $D $"7 7d 7t3l
 zF r   