
    Sܶi[                         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             dS dS )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{V }t          |d           }g d}d |D             }t          t          ||                     dS )zPrint all available voices.r   Nc                     | d         S )N	ShortName )voices    P/root/projects/openclaw-proxy/venv/lib/python3.11/site-packages/edge_tts/util.py<lambda>z_print_voices.<locals>.<lambda>   s    eK.@     )key)NameGenderContentCategoriesVoicePersonalitiesc           	          g | ]R}|d          |d         d                     |d         d                   d                     |d         d                   gSS )r   r   z, VoiceTagr   r   )join).0r   s     r   
<listcomp>z!_print_voices.<locals>.<listcomp>   so         +(OIIeJ'(;<==IIeJ'(<=>>		
  r   )r	   sortedprintr   )r   voicesheaderstables       r   _print_voicesr'      s      U+++++++++FF @ @AAAFKKKG    E 
(5'
"
"#####r   argsc                   K   	 t           j                                        rNt           j                                        r0| j        s)t          dt           j                   t                       n,# t          $ r t          dt           j                   Y dS w xY wt          | j
        | j        | j        | j        | j        | j                  }t!                      }	 | j         | j        dk    rt#          | j        d          nt           j        j        }| j        "| j        dk    rt#          | j        dd	
          nd}|| j        dk    rt           j        }|                                2 3 d{V }|d         dk    r|                    |d                    /|d         dv r|                    |           O6 |'|                    |                                           |t           j        j        ur|                                 |$|t           j        ur|                                 dS dS dS # |t           j        j        ur|                                 |#|t           j        ur|                                 w w w xY 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_ttsrO   !   s     9 	#*"3"3"5"5 	d>N 	+ Z    GGG   %CJ7777 	
Y{jj  K zzH +0@C0G0G !4(((" 	 #/D4HC4O4O %sW==== 	
  4 ; ;zH&--// 	% 	% 	% 	% 	% 	% 	%%V}''  v////v"FFFe$$$	 0 NN8++--...SZ...HCJ$>$>NN  $>$> SZ...HCJ$>$>NN  $>s-   A,A1 1%BBBH9 /F>5A3H9 9AJc                  z  K   t          j        d          } |                     d          }|                    ddd           |                    d	d
d           |                     dddt           t                     |                    dddd           |                     ddd           |                     ddd           |                     ddd           |                     dd           |                     dd            |                     d!d"           |                     d#d$d%t
           &           |                     t                      '          }|j        r/t          |j
        (           d){V  t          j        d*           |j        t|j        d+v r$t          j                                        |_        nGt#          |j        d,-          5 }|                                |_        d)d)d)           n# 1 swxY w Y   |j        t%          |           d){V  d)S d)S ).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: )rS   defaultz-lz--list-voicesz lists available voices and exits
store_true)rS   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 )rV   rW   )	namespacer   Nr   )r.   z
/dev/stdinr1   r2   )argparseArgumentParseradd_mutually_exclusive_groupadd_argumentr
   r   
parse_argsr   r	   r'   r   r9   exitr*   r:   readrA   rB   rO   )parsergroupr(   r*   s       r   amainrb   X   s     $O  F ///>>E	tX,?@@@	tX,OPPP
777	     
/	     'DeTTT

)HRWXXX
	(FPVWWW
K     F     	(MNNN
I/H;/H/H     xzz22D $*----------y9+++	((DIIdi'222 (d IIKK	( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ytnn s   ,HHHc                  F    t          j        t                                 dS )z$Run the main function using asyncio.N)asynciorunrb   r   r   r   mainrf      s    Kr   __main__)r   N)__doc__rY   rd   r9   typingr   r   r    r   r   r	   	constantsr
   data_classesr   rW   r   strr'   rO   rb   rf   __name__r   r   r   <module>ro      s:   P P   



 # # # # # # # #       0 0 0 0 0 0 0 0 0 0 $ $ $ $ $ $ " " " " " "            $(3- $D $ $ $ $"4 4d 4 4 4 4n0 0 0 0f   
 zDFFFFF r   