o
    m=8j[                     @   s   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dZdeddfddZdddZd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                    sJ   t | dI dH }t|dd d}g d}dd |D }tt|| dS )	zPrint all available voices.r   Nc                 S   s   | d S )N	ShortName )voicer   r   T/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/edge_tts/util.py<lambda>   s    z_print_voices.<locals>.<lambda>)key)NameGenderContentCategoriesVoicePersonalitiesc              	   S   s<   g | ]}|d  |d d |d d d |d d gqS )r   r   z, VoiceTagr   r   )join).0r   r   r   r   
<listcomp>   s    z!_print_voices.<locals>.<listcomp>)r   sortedprintr   )r   voicesheaderstabler   r   r   _print_voices   s   	r"   argsc                    s  zt j rt j r| jstdt jd t  W n ty+   tdt jd Y dS w t	| j
| j| j| j| j| jd}t }z| jdurP| jdkrPt| jdnt jj}| jdurf| jdkrft| jdd	d
nd}|du rt| jdkrtt j}| 2 z3 dH W }|d dkr||d  qx|d dv r|| qx6 |dur||  W |t jjur|  |dur|t jur|  dS dS dS |t jjur|  |dur|t jur|  w 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chunkr   r   r   _run_tts!   sj   

rI   c                     s~  t jdd} | jdd}|jdddd |jd	d
dd | jdddt td |jddddd | jdddd | jdddd | jdddd | jddd | jdd d | jd!d"d | jd#d$d%t d& | jt d'}|jrt	|j
d(I d)H  td* |jd)ur|jd+v rtj |_nt|jd,d-}| |_W d)   n1 sw   Y  |jd)urt|I d)H  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: )rL   defaultz-lz--list-voicesz lists available voices and exits
store_true)rL   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 )rO   rP   )	namespacer   Nr   )r(   z
/dev/stdinr+   r,   )argparseArgumentParseradd_mutually_exclusive_groupadd_argumentr	   r   
parse_argsr
   r   r"   r   r3   exitr$   r4   readr;   r<   rI   )parsergroupr#   r$   r   r   r   amainX   s\   



r[   c                   C   s   t t  dS )z$Run the main function using asyncio.N)asynciorunr[   r   r   r   r   main   s   r^   __main__)r   N)__doc__rR   r\   r3   typingr   r   r    r   r   r   	constantsr	   data_classesr
   rP   r   strr"   rI   r[   r^   __name__r   r   r   r   <module>   s"    
7
3
