+
   ^׸+Tc                   s   ^ RI Ht ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
]P                  ! R4      tRt ^ RItRtRt ^ RItRtRt ^ RItRt ! R R4      tR	 R
 lt]R8X  dS   ]P0                  ! ]P2                  R7      t]P7                  ]P8                  4       ]P;                  ]4       ]! 4        R# R#   ]3 d    Rt Li ; i  ]3 d    Rt Li ; i  ]3 d    Rt Li ; i)    )Optional)AnyNzibus-typing-boosterFTc                   sV  a  ] tR t^9t o R=V 3R lR lltV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR  lt]V 3R! lR" l4       t]V 3R# lR$ l4       t]V 3R% lR& l4       t]V 3R' lR( l4       tV 3R) lR* ltV 3R+ lR, ltV 3R- lR. ltV 3R/ lR0 ltV 3R1 lR2 ltV 3R3 lR4 ltV 3R5 lR6 ltV 3R7 lR8 lt V 3R9 lR: lt!R;t"V t#R<# )>SoundObjectc                s*   < V ^8  d   QhRS[ RS[ RR/# )   path_to_sound_fileaudio_backendreturnNZstrformat__classdict__   "2/usr/share/ibus-typing-booster/engine/itb_sound.py__annotate__SoundObject.__annotate__@   s*     [ [%([ #[6:[    c                sV   Wn         R V n        R V n        R V n        R V n        R V n        R V n        R V n        RV n        R V n	        R V n
        R	V n        W n        RV n        \        P                  P!                  V P                   4      '       g   \"        P%                  RV4       R # \        P&                  ! V P                   \        P(                  4      '       g   \"        P%                  RV4       R # V P                  V P                  9  d#   \"        P+                  RW P                  4       R # \-        V RV P                   24      ! 4       V n        V P                  '       d#   \"        P%                  RV P                  4       R # \"        P+                  RV P                  4       R # )
Nr    zSound file %s does not exist.zSound file %s not readable.z-Audio backend %s not supported, use one of %sZ_init_zUsing audio backend %szCould not init audio backend %s)	automaticpygamesimpleaudioaplaypyaudio)_path_to_sound_file	_wav_file_paudio_play_pyaudio_thread_stop_event_paudio_simpleaudio_wave_o_simpleaudio_play_o_aplay_binary_aplay_stdin_aplay_process_play_aplay_thread_supported_audio_backends_requested_audio_backend_audio_backendosZpathZisfileLOGGERinfoZaccessZR_OKerrorgetattr)selfr   r   s   &&&r   __init__ZSoundObject.__init__@   sN    ); 3726@D!=AEI KO ,0-1>B)c&(5% ww~~d6677KK79KLyy11277;;KK57IJ((0N0NNLLH&(F(FH%dfT5R5R4S,TUWKK0$2E2EFLL:D<Y<YZr   c                    < V ^8  d   QhRS[ /# r   r   r   r	   r   r   r   r   a   s          r   c                s(   V P                  4       '       d   R # \        P                  P                  \        P                  P                  \        P                  P
                  3R8  d   V P                  4       '       d   R# V P                  4       '       d   R# \        '       d   \        P                  P                  \        P                  P                  \        P                  P
                  3R8  g   \        P                  '       d   \        ;QJ d1    . R \        P                  P                  R4       4       F  NK  	  5M*! R \        P                  P                  R4       4       4      R	8  d   V P                  4       '       d   R# R# )
r   r   r   c              3   s8   "   T F  p\        V4      x  K  	  R # 5iN)Zint)Z.0Zx   & r   Z	<genexpr>Z.SoundObject._init_automatic.<locals>.<genexpr>}   s     C$BqCFF$Bs   Z.r   r   )      r    )r0   i
   r    )r    r   r1   )_init_pygamesysZversion_infoZmajorZminorZmicro_init_simpleaudio_init_aplayIMPORT_PYAUDIO_SUCCESSFULr   Z__version__ZtupleZsplit_init_pyaudior*      &r   _init_automaticZSoundObject._init_automatica   s   
 ######%'12 %%''$
 &%%%%%%%')34 !!!eCG$7$7$=$=c$BCeeCG$7$7$=$=c$BCCzQ!!## r   c                r,   r-   r   r	   r   r   r   r      s      c r   c                s   \         '       g   R #  \        P                  P                  RR7       \        P                  P	                  4       '       d6   \        P                  P
                  P                  V P                  4       R#  R #   \         d7   p\        P                  RTP                  P                  T4        Rp?R # Rp?ii ; i)r   i   )Zbufferr   z%pygame: cannot load sound file %s: %sN)IMPORT_PYGAME_MIXER_SUCCESSFULr   mixerZinitZget_initmusicZloadr   	Exceptionr&   	exception	__class____name__r*   r(   r/   r   r2   ZSoundObject._init_pygame   s    --	1 LLT*||$$&&""''(@(@A ' 	  	17((%1 1 		1s   AB 3B C+CCc                r,   r-   r   r	   r   r   r   r      s      s r   c                sJ   \         '       g   R # \        P                  ! V P                  4      w  rVR9  d$   \        P                  RV P                  V4       R #  \        P                  ! V P                  R4      V n        \        P                  ! 4       V n        \        P                  ! 4       V n        \        P                  R\        P                   ! 4       4       R#   \"         d7   p\        P%                  RTP&                  P(                  T4        Rp?R # Rp?ii ; i)r   <File %s has mime type %s and is not supported by simpleaudiorbzportaudio version = %sr   z'pyaudio: cannot init wave object %s: %sNaudio/x-wav)r6   	mimetypes
guess_typer   r&   r(   waveopenr   r   ZPyAudior   	threadingEventr   r'   Zget_portaudio_version_textr>   r?   r@   rA   r*   	mime_type	_encodingr(      &   r   r7   ZSoundObject._init_pyaudio   s    ((!*!5!5d6N6N!O,,LLN(()5 
	1!YYt'?'?FDN"??,DL&/oo&7D#KK0::<> 	19((%1 1 		1s   BC! !D",+DD"c                r,   r-   r   r	   r   r   r   r      s      3 r   c                s   \         '       g   R # \        P                  ! V P                  4      w  rVR9  d$   \        P                  RV P                  V4       R #  \        P                  P                  V P                  4      V n	        R#   \         d7   p\        P                  RTP                  P                  T4        Rp?R # Rp?ii ; i)r   rC   r   .Initializing error sound object failed: %s: %sNrE   )IMPORT_SIMPLEAUDIO_SUCCESSFULrG   rH   r   r&   r(   r   Z
WaveObjectZfrom_wave_filer   r>   r?   r@   rA   rM   rP   r   r4   ZSoundObject._init_simpleaudio   s    ,,!*!5!5d6N6N!O,,LLN(()5 	1&&55d6N6NO $  	1@((%1 1 		1s   .B C+CCc                r,   r-   r   r	   r   r   r   r      s      S r   c                s   \         P                  ! V P                  4      w  rVR9  d$   \        P	                  RV P                  V4       R# \
        P                  ! R4      V n        V P                  '       g   R# \        V P                  RR7      ;_uu_ 4       pVP                  4       V n
        V P                  '       d    RRR4       R#  RRR4       R#   + '       g   i     R# ; i)rF   z6File %s has mime type %s and is not supported by aplayr   r   rD   )ZmodeNrE   )rG   rH   r   r&   r(   shutilZwhichr   rJ   Zreadr   )r*   rN   rO   Zaplay_inputrP   r   r5   ZSoundObject._init_aplay   s    !*!5!5d6N6N!O,,LLH(()5 #\\'2!!!4++$77; + 0 0 2D    87  8 	 87 s   )CC*	c                   < V ^8  d   QhRR/# r   r   N r	   r   r   r   r      s     # # #r   c                s    V P                   '       d   V P                   P                  4        V P                  '       d   V P                  P                  4        R # R # r.   )r   	terminater   closer8   r9   r   __del__ZSoundObject.__del__   s9    <<<LL""$>>>NN  " r   c                s8   < V ^8  d   QhRS[ P                  RR/# )r   
stop_eventr   N)rK   rL   r	   r   r   r   r      s     '8 '8	 '8D '8r   c                st   V P                   '       g#   \        P                  R V P                  4       R# V P                  '       g   \        P                  R4       R# \        P                  R4       RpV P                  P                  V P                  P                  V P                   P                  4       4      V P                   P                  4       V P                   P                  4       RVR7      pV P                   P                  4        V P                   P                  V4      pV'       dr   VP                  4       '       g\    VP                  4       '       g   \        P                  R4       M.VP                  V4       V P                   P                  V4      pKy  VP+                  4        VP-                  4        \        P                  R
4       R#   \         \"        3 dL   p\        P%                  RTP&                  P(                  T4       \        P                  R	4        Rp?K  Rp?ii ; i)z!wave.open(%s, 'rb') did not work.Nzpyaudio.PyAudio() did not work.zPlaying sound with pyaudio ...i   T)r
   ZchannelsZrateZoutputZframes_per_bufferz#pyaudio stream is_active() is Falsez+Unexpected error playing wave object %s: %szIf you see the "SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats" message here, updating to pyaudio >= 0.2.12 will probably fix the problem.See https://stackoverflow.com/questions/70344884z Done playing sound with pyaudio.)r   r&   r(   r   r   r'   rJ   Zget_format_from_widthZgetsampwidthZgetnchannelsZgetframeraterewindZ
readframesis_setZ	is_activeZwriteZSystemErrorOSErrorr?   r@   rA   Zstop_streamrX   )r*   rZ   Z
chunk_sizestreamZdatar(   s   &&    r   _play_pyaudio_thread_functionZ)SoundObject._play_pyaudio_thread_function   s   ~~~LL>113|||LL:;45
""<<55++-/^^002,,.( # * 	~~((4:,,..''))LL!FGT"~~00< 	67  ) 
  AOO,,e5  P Q 
s%   
G  G 6,G H7,A H22H7c                rT   rU   rV   r	   r   r   r   r      s     * *t *r   c                s    V P                   '       d   V P                   P                  4        \        P                  ! R V P                  V P                   3R7      V n        V P
                  P                  4        R# )T)daemontargetZargsN)r   clearrK   Threadr_   r   startr8   r9   r   _play_pyaudioZSoundObject._play_pyaudio   s_    """##))+$-$4$455))+%-! 	!!'')r   c                r,   r-   boolr	   r   r   r   r     s     4 4T 4r   c                ^    V P                   '       g   R # V P                   P                  4       # F)r   is_aliver8   r9   r   _is_playing_pyaudioZSoundObject._is_playing_pyaudio  s&    (((((1133r   c                rT   rU   rV   r	   r   r   r   r     s     	, 	,t 	,r   c                sz   V P                   '       g   R # V P                  '       g   R # V P                   P                  4       '       ds   V P                  P                  4       '       gQ   V P                  P	                  4        V P                   P                  4        V P                  P                  4        R # R # R # r.   )r   r   rj   r\   Zsetjoinrb   r8   r9   r   _stop_pyaudioZSoundObject._stop_pyaudio  s    (((&&&%%..00++2244##'')%%**,##))+ 5 1r   c                rT   rU   rV   r	   r   r   r   r     s     - -D -r   c                    V P                   '       g   R # V P                   P                  4       '       d   V P                   P                  4        R # R # r.   )r   rj   rl   r8   r9   r   _wait_done_pyaudioZSoundObject._wait_done_pyaudio  s=    ((($$--//%%**, 0r   c                rT   rU   rV   r	   r   r   r   r     s     1 14 1r   c                s    V P                   '       g   R #  V P                   P                  4       V n        R #   \         d7   p\        P                  RTP                  P                  T4        R p?R # R p?ii ; i)NrQ   )r   playr   r>   r&   r?   r@   rA   rB   r/   r   _play_simpleaudioZSoundObject._play_simpleaudio  sb    '''	1'+'?'?'D'D'FD$ 	1@((%1 1	1s   7 A8+A33A8c                r,   r-   rf   r	   r   r   r   r   '  s     ; ; ;r   c                sp    V P                   '       g   R # \        V P                   P                  4       4      # ri   )r   rg   
is_playingr8   r9   r   _is_playing_simpleaudioZ#SoundObject._is_playing_simpleaudio'  s+    '''D,,779::r   c                rT   rU   rV   r	   r   r   r   r   ,  s     - -4 -r   c                s    V P                   '       g   R # V P                   P                  4        V P                   P                  4        R # r.   )r   stop	wait_doner8   r9   r   _stop_simpleaudioZSoundObject._stop_simpleaudio,  s7    '''  %%' 	  **,r   c                rT   rU   rV   r	   r   r   r   r   4  s     - - -r   c                sb    V P                   '       g   R # V P                   P                  4        R # r.   )r   ru   r8   r9   r   _wait_done_simpleaudioZ"SoundObject._wait_done_simpleaudio4  s#    '''  **,r   c                rT   rU   rV   r	   r   r   r   r   :  s     " "$ "r   c                 s    \         P                  P                  P                  4        \         P                  P                  P	                  4        R # r.   )r   r<   r=   r[   rp   rV   r   r   _play_pygameZSoundObject._play_pygame9  s.    !!#!r   c                r,   r-   rf   r	   r   r   r   r   ?  s     - - -r   c                 sR    \         P                  P                  P                  4       # r.   r   r<   r=   Zget_busyrV   r   r   _is_playing_pygameZSoundObject._is_playing_pygame>  s    ||!!**,,r   c                rT   rU   rV   r	   r   r   r   r   C  s     " "$ "r   c                 sV    \         P                  P                  P                  4        R # r.   )r   r<   r=   rt   rV   r   r   _stop_pygameZSoundObject._stop_pygameB  s    !r   c                rT   rU   rV   r	   r   r   r   r   G  s      t r   c                 sf    \         P                  P                  P                  4       '       d   K0  R # r.   ry   rV   r   r   _wait_done_pygameZSoundObject._wait_done_pygameF  s#    ll  ))++ ,r   c                rT   rU   rV   r	   r   r   r   r   K  s     '6 '6T '6r   c                sV   V P                   '       g   R #  \        P                  ! RR\        P                  \        P                  \        P                  R R R R7      V n         T P                  P                  T P                  RR7        T P                  P                  4        R #   \
        \        3 d7   p\        P                  RTP                  P                  T4        R p?R # R p?ii ; i  \        P                   dQ   p\        P                  RTP                  P                  T4       T P                  P                  4         R p?R # R p?ii ; i  \          d   p\        P                  RTP                  P                  T4        \        P#                  R	4       T P                  P                  4        \        P#                  R
4        R p?R #   \          d;   p\        P                  RTP                  P                  T4        R p? R p?R # R p?ii ; iR p?ii ; i)Nr   F)ZshellZstdinstderrZstdoutZencodingZerrorsZtextz!cannot start aplay process %s: %si  )Zinputtimeoutz2timeout piping sound file into aplay process%s: %s%cannot terminate aplay process %s: %sTrying to kill aplay processzaplay process killedcannot kill aplay process%s: %s)r   
subprocessZPopenZPIPEr    r]   Z
ValueErrorr&   r?   r@   rA   Zcommunicater   ZTimeoutExpiredkillrW   r>   r'   r*   r(   Zerror2   &  r   _play_aplay_thread_functionZ'SoundObject._play_aplay_thread_functionK  s   !!!	","2"2u oo!!#D	++$2C2C48 , :	6))+ $ 	3((%1 		 (( 	D((%1 $$&	  	67((%16:;##((*233 6  5OO,,f6 66	6sn   AB( $'C2 E (C/9+C**C/2EAEEH(%+H#AGH &+HH#H  H##H(c                rT   rU   rV   r	   r   r   r   r   t  s     ( (T (r   c                s    \         P                  ! R V P                  R7      V n        V P                  P	                  4        R# )T)r`   ra   N)rK   rc   r   r!   rd   r8   r9   r   _play_aplayZSoundObject._play_aplayt  s5    "+"2"233#5 	%%'r   c                r,   r-   rf   r	   r   r   r   r   z  s     2 24 2r   c                rh   ri   )r!   rj   r8   r9   r   _is_playing_aplayZSoundObject._is_playing_aplayz  s&    &&&&&//11r   c                rT   rU   rV   r	   r   r   r   r     s     > >T >r   c                s`   V P                   '       g   R # V P                   P                  4       '       dJ   V P                  '       d8   V P                  P                  4       f    V P                  P	                  4        V P                   P                  4       '       dV   V P                   P                  RR7       V P                   P                  4       '       d   \        P                  R4       R # R # R #   \
         d   p\        P                  RTP                  P                  T4        \        P                  R4       T P                  P                  4         R p?L  \
         d;   p\        P                  RTP                  P                  T4        R p? R p?EL"R p?ii ; iR p?ii ; i)Nr   r   r   g?)r~   ztimeout stopping aplay thread)r!   rj   r    ZpollrW   r>   r&   r?   r@   rA   r'   r   rl   r(   r   r   r   _stop_aplayZSoundObject._stop_aplay  sE   &&&##,,..#####((*2:##--/ ""++--##(((5&&//11<= 2 .  
:  7((%1:KK >?'',,..  :$$900&: ::
:s<   $C5 5F- +F(,/E  F%++F F( F%%F((F-c                rT   rU   rV   r	   r   r   r   r     s     + +$ +r   c                rn   r.   )r!   rj   rl   r8   r9   r   _wait_done_aplayZSoundObject._wait_done_aplay  s=    &&&""++--##((* .r   c                rT   rU   rV   r	   r   r   r   r          8 8d 8r   c                    V P                   '       g#   \        P                  R V P                  4       R# \	        V RV P                    24      ! 4        R# )#Could not init any audio backend %sNZ_play_r$   r&   r(   r#   r)   r8   r9   r   rp   ZSoundObject.play  D    """LL>668t223457r   c                r,   r-   rf   r	   r   r   r   r     s     K KD Kr   c                s    V P                   '       g#   \        P                  R V P                  4       R# \	        \        V RV P                    24      ! 4       4      # )r   FZ_is_playing_)r$   r&   r(   r#   rg   r)   r8   r9   r   rr   ZSoundObject.is_playing  sL    """LL>668GDL1D1D0E"FGIJJr   c                rT   rU   rV   r	   r   r   r   r     r   r   c                r   )r   NZ_stop_r   r8   r9   r   rt   ZSoundObject.stop  r   r   c                rT   rU   rV   r	   r   r   r   r     s     = =4 =r   c                r   )r   NZ_wait_done_r   r8   r9   r   ru   ZSoundObject.wait_done  sD    """LL>668D$7$7#89:<r   )r   r    r   r$   r   r   r!   r   r#   r   r   r   r"   r   N)r   )$rA   Z
__module__Z__qualname__Z__firstlineno__r+   r:   r2   r7   r4   r5   rY   r_   re   rk   rm   ro   rq   rs   rv   rw   Zstaticmethodrx   rz   r{   r|   r   r   r   r   r   rp   rr   rt   ru   Z__static_attributes__Z__classdictcell__)r   s   @r   r   r   9   sW    [ [B   D & , &  # #'8 '8R* *4 4
	, 	,- -1 1; ;
- -- -
 " " - - " "  '6 '6R( (2 2
> >0+ +8 8K K8 8= =r   r   c                s    V ^8  d   QhRR/# rU   rV   )r
   s   "r   r   r     s      4 r   c                  s   R p \        RV R7      pVP                  4        VP                  4        VP                  4        VP                  4        ^ RIp\        RV R7      pVP                  4        \        P                  R4       VP                  ^4       \        P                  RVP                  4       4       VP                  4        \        P                  RVP                  4       4       VP                  ^4       R# )r   z-/usr/share/ibus-typing-booster/data/coin9.wav)r   NuI   /home/mfabian/sounds/japanese/今回もよろしくお願いします.wavzSleeping ...zis playing %s)	r   rp   ru   timer&   r'   Zsleeprr   rt   )r   Zsound_objectr   s      r   	run_testsr     s      M7#	%L
  S#%L 
KKJJqM
KK!8!8!:;
KK!8!8!:;JJqMr   Z__main__)r^   )Ztypingr   r   r3   r%   ZloggingrK   rI   rS   r   rG   Z	getLoggerr&   r;   Zpygame.mixerr   ZImportErrorr6   r   rR   r   r   r   rA   ZStreamHandlerr}   ZLOG_HANDLERZsetLevelZDEBUGZ
addHandlerrV   r   r   <module>r      s  .   
 	      			0	1!& +%)" " & $ !& *$(!B= B=H< z''szz:K
OOGMM"
k"K g 	~ +%*"+ 	~ & %& 	~ *$)!*s6   C C C% 
CC
C"!C"%
C21C2