o
    êi
                  	   @   st   d Z ddlZddlZddlmZmZ ddlmZ dede	fdd	Z
d
dddeeee f de	de	ddfddZdS )zAudio playback utility.    N)IterableUnion   )DependencyErrorcommandreturnc                 C   s2   zt jd| gddd W dS  t jy   Y dS w )z(Check if a command is available in PATH.whichT)capture_outputcheckF)
subprocessrunCalledProcessError)r    r   H/home/ubuntu/.local/lib/python3.10/site-packages/fishaudio/utils/play.py_is_installed
   s   r   FT)notebook
use_ffmpegaudior   r   c          	      C   s   t | ts
d| } |r-zddlm}m} ||| ddd W dS  ty,   tdd	w |rQtd
s8td
dzt	j
g d| ddd W dS  t	jyP   Y nw z
ddl}ddl}W n tyg   tddw |t| \}}||| |  dS )a  
    Play audio using various playback methods.

    Args:
        audio: Audio bytes or iterable of bytes
        notebook: Use Jupyter notebook playback (IPython.display.Audio)
        use_ffmpeg: Use ffplay for playback (default, falls back to sounddevice)

    Raises:
        DependencyError: If required playback tool is not installed

    Examples:
        ```python
        from fishaudio import FishAudio, play

        client = FishAudio(api_key="...")
        audio = client.tts.convert(text="Hello world")

        # Play directly
        play(audio)

        # In Jupyter notebook
        play(audio, notebook=True)

        # Force sounddevice fallback
        play(audio, use_ffmpeg=False)
        ```
        r   )AudiodisplayiD  T)rateautoplayNIPythonzpip install ipythonffplayzibrew install ffmpeg  # macOS
sudo apt install ffmpeg  # Linux
https://ffmpeg.org/download.html  # Windows)r   z	-autoexit-z-nodisp)inputr	   r
   zsounddevice and soundfilezFpip install 'fishaudio[utils]'  # or
pip install sounddevice soundfile)
isinstancebytesjoinIPython.displayr   r   ImportErrorr   r   r   r   r   sounddevice	soundfilereadioBytesIOplaywait)	r   r   r   r   r   sdsfdata
samplerater   r   r   r'      sN   
#

r'   )__doc__r%   r   typingr   r   
exceptionsr   strboolr   r   r'   r   r   r   r   <module>   s"    