
    rh                     D    S r SSKrSSKJr  SSKJrJr  S rS rS r	S	 r
g)
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                     [        5       n[        SSS9 nU R                  UR                  S5        [        R
                  " USSSUR                  /5        S S S 5        g ! , (       d  f       g = f)Nzw+bz.wav)suffixwavz-nodispz	-autoexitz-hide_banner)r   r   exportname
subprocesscall)segPLAYERfs      H/home/james-whalen/.local/lib/python3.13/site-packages/pydub/playback.py_play_with_ffplayr      sO    F	E&	1Q

1665!KPQ 
2	1	1s   AA  
A.c                    SS K nUR                  5       nUR                  UR                  U R                  5      U R
                  U R                  SS9n [        U S5       H  nUR                  UR                  5        M      UR                  5         UR                  5         UR                  5         g ! UR                  5         UR                  5         UR                  5         f = f)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    AVV12233C3CD \\  !F c*ELL% + 		 		s   .B4 42C&c                 ~    SS K nUR                  U R                  U R                  U R                  U R
                  S9$ )Nr   )num_channelsbytes_per_samplesample_rate)simpleaudioplay_bufferraw_datar   r   r   )r   r+   s     r   _play_with_simpleaudior.   )   s;    ""\\))NN	 #      c                      [        U 5      n UR                  5         g ! [         a    UR                  5          g f = f! [         a     Of = f [        U 5        g ! [         a     Of = f[        U 5        g )N)r.   	wait_doneKeyboardInterruptstopImportErrorr&   r   )audio_segmentplaybacks     r   playr7   3   s    	)-8	  	 ! 	MMO 		 
=) 
 m$s5   ?  <? <? 
AAA 
A)(A))__doc__r   tempfiler   utilsr   r   r   r&   r.   r7    r/   r   <module>r<      s*     ' /R,%r/   