
    >|hd              	           d dl Z d dlZd dlmZmZ dedefdZ	 	 ddeeee   f   dededdfd	Z	deeee   f   d
eddfdZ
dee   defdZy)    N)IteratorUnionlib_namereturnc                 4    t        j                  |       }|yy)NFT)shutilwhich)r   libs     N/var/www/html/test/engine/venv/lib/python3.12/site-packages/elevenlabs/play.pyis_installedr      s    
,,x
 C
{    audionotebook
use_ffmpegc                    t        | t              rdj                  |       } |r	 ddlm}m}  | || dd             y |rt        d      sd	}t        |      g d
}t        j                  |t        j                  t        j                  t        j                        }|j                  |       \  }}	|j                          y 	 dd l}
dd l}dd l} |j"                  |j%                  |
j'                  |               |j)                          y # t        $ r d}t        |      w xY w# t        $ r d}t        |      w xY w)Nr   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sfs                r   r*   r*      s0   
 %"	&6 	e%$78	H%S 
 W%%6??//??	
 ##%#0S				&$" 	E*+,
	I # 	&G  W%%		&< # 	&W  W%%		&s   D D+ D(+Efilenamec                     t        | t              rdj                  |       } t        |d      5 }|j	                  |        d d d        y # 1 sw Y   y xY w)Nr   wb)r   r   r   openwrite)r   r4   fs      r   saver:   >   sE    %"	h	 	  s   A		Aaudio_streamc                    t        d      sd}t        |      g d}t        j                  |t        j                  t        j
                  t        j
                        }d}| D ]?  }||j                  j                  |       |j                  j                          ||z  }A |j                  r|j                  j                          |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/)r=   z
--no-cachez--no-terminalz--zfd://0)r   r   r   r   )r   r!   r"   r#   r$   DEVNULLr   r8   flushcloser-   )r;   r.   mpv_commandmpv_processr   chunks         r   streamrD   E   s    K 	
 !!HK""oo!!!!	K E ##E*##%UNE	
 !Lr   )FT)r   r"   typingr   r   strboolr   bytesr*   r:   rD    r   r   <module>rJ      s      "3 4  .'(.. . 
	.beXe_,-   % U r   