
    #)di                     F    d Z ddlZddlmZ ddlmZmZ d Zd Zd Z	d	 Z
dS )
a$  
Support for playing AudioSegments. Pyaudio will be used if it's installed,
otherwise will fallback to ffplay. Pyaudio is a *much* nicer solution, but
is tricky to install. See my notes on installing pyaudio in a virtualenv (on
OSX 10.10): https://gist.github.com/jiaaro/9767512210a1d80a8a0d
    N)NamedTemporaryFile   )get_player_namemake_chunksc                     t                      }t          dd          5 }|                     |j        d           t	          j        |ddd|j        g           d d d            d S # 1 swxY w Y   d S )Nzw+bz.wav)suffixwavz-nodispz	-autoexitz-hide_banner)r   r   exportname
subprocesscall)segPLAYERfs      U/var/www/menimich/repos/protonApp/venv/lib/python3.11/site-packages/pydub/playback.py_play_with_ffplayr      s    F	E&	1	1	1 RQ

165!!!KPQQQR R R R R R R R R R R R R R R R R Rs   :A''A+.A+c                    dd l }|                                }|                    |                    | j                  | j        | j        d          }	 t          | d          D ]}|                    |j	                   	 |
                                 |                                 |                                 d S # |
                                 |                                 |                                 w xY w)Nr   T)formatchannelsrateoutputi  )pyaudioPyAudioopenget_format_from_widthsample_widthr   
frame_rater   write_datastop_streamclose	terminate)r   r   pstreamchunks        r   _play_with_pyaudior&      s    NNNAVV12233CDD \  ! !F c** 	& 	&ELL%%%%	& 		 		s   -C >C?c                 d    dd l }|                    | j        | j        | j        | j                  S )Nr   )num_channelsbytes_per_samplesample_rate)simpleaudioplay_bufferraw_datar   r   r   )r   r+   s     r   _play_with_simpleaudior.   )   s@    ""\)N	 #       c                     	 t          |           }	 |                                 n$# t          $ r |                                 Y nw xY wd S # t          $ r Y nw xY w	 t          |            d S # t          $ r Y nw xY wt          |            d S )N)r.   	wait_doneKeyboardInterruptstopImportErrorr&   r   )audio_segmentplaybacks     r   playr7   3   s    	)-88	      	 	 	MMOOOOO	
 	    
=)))   
 m$$$$$sC   A ' A AA AA 
AAA/ /
A<;A<)__doc__r   tempfiler   utilsr   r   r   r&   r.   r7    r/   r   <module>r<      s         ' ' ' ' ' ' / / / / / / / /R R R  ,  % % % % %r/   