o
    lWid                  	   @   s   d dl Z d dlZd dlmZmZ dedefddZ		dd	eeee f d
ededdfddZ	d	eeee f deddfddZ
dee defddZdS )    N)IteratorUnionlib_namereturnc                 C   s   t | }|d u rdS dS )NFT)shutilwhich)r   lib r	   S/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/play.pyis_installed   s   
r   FTaudionotebook
use_ffmpegc                 C   s  t | tr
d| } |r/z
ddlm}m} W n ty#   d}t|w ||| ddd d S |rYtds;d	}t|g d
}t	j
|t	jt	jt	jd}|j| d\}}	|  d S zdd l}
dd l}dd l}W n tyt   d}t|w |j||
|   |  d S )N    r   )Audiodisplayz5`pip install ipython` required when `notebook=False` iD  T)rateautoplayffplayzffplay from ffmpeg not found, necessary to play audio. On mac you can install it with 'brew install ffmpeg'. On linux and windows you can install it from https://ffmpeg.org/)r   z	-autoexit-z-nodisp)argsstdoutstdinstderr)inputzE`pip install sounddevice soundfile` required when `use_ffmpeg=False` )
isinstancer   joinIPython.displayr   r   ModuleNotFoundError
ValueErrorr   
subprocessPopenPIPEcommunicatepolliosounddevice	soundfileplayreadBytesIOwait)r   r   r   r   r   messager   procouterrr%   sdsfr	   r	   r
   r(      sH   

r(   filenamec                 C   sN   t | tr
d| } t|d}||  W d    d S 1 s w   Y  d S )Nr   wb)r   r   r   openwrite)r   r2   fr	   r	   r
   save>   s
   

"r7   audio_streamc                 C   s   t ds
d}t|g d}tj|tjtjtjd}d}| D ]}|d ur3|j| |j  ||7 }q|jr<|j	  |
  |S )Nmpvzmpv not found, necessary to stream audio. On mac you can install it with 'brew install mpv'. On linux and windows you can install it from https://mpv.io/)r9   z
--no-cachez--no-terminalz--zfd://0)r   r   r   r   )r   r   r    r!   r"   DEVNULLr   r5   flushcloser+   )r8   r,   mpv_commandmpv_processr   chunkr	   r	   r
   streamE   s,   

r@   )FT)r   r    typingr   r   strboolr   bytesr(   r7   r@   r	   r	   r	   r
   <module>   s"    	
"1