%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/ibus-table/engine/__pycache__/
Upload File :
Create Path :
Current File : //usr/share/ibus-table/engine/__pycache__/it_sound.cpython-312.pyc

�

��Xe�F����dZddlmZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZejd�Z
dZ	ddlZdZdZ	ddlZdZdZ	ddlZdZGd�d	�Zd
d
�Zedk(rQej2ej4��Ze
j9ej:�e
j=e�e�yy#ef$rdZY��wxYw#ef$rdZY��wxYw#ef$rdZY��wxYw)z$
Module to play simple error sounds
�)�Optional)�AnyNz
ibus-tableFTc�t�eZdZdZ	d$dededdfd�Zdefd�Zdefd�Zdefd	�Zdefd
�Z	defd�Z
d%d�Zd
ejddfd�Zd%d�Zdefd�Zd%d�Zd%d�Zd%d�Zdefd�Zd%d�Zd%d�Zed%d��Zedefd��Zed%d��Zed%d��Zd%d�Zd%d�Zdefd�Zd%d�Z d%d�Z!d%d �Z"defd!�Z#d%d"�Z$d%d#�Z%y)&�SoundObjectz�
    Class to play sounds

    When pygames is used, this can play .wav and .mp3 files.
    When pyaudio is used, only .wav files work.
    �path_to_sound_file�
audio_backend�returnNc��||_d|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
||_d|_tjj|j�st j#d|�ytj$|jtj&�st j#d|�y|j|jvr"t j)d||j�yt+|d|j����|_|jr!t j#d|j�yt j)d	|j�y)
N�)�	automatic�pygame�simpleaudio�aplay�pyaudio�zSound file %s does not exist.zSound file %s not readable.z-Audio backend %s not supported, use one of %s�_init_zUsing audio backend %szCould not init audio backend %s)�_path_to_sound_file�	_wav_file�_paudio�_play_pyaudio_thread�_simpleaudio_wave_o�_simpleaudio_play_o�
_aplay_binary�_aplay_stdin�_aplay_process�_play_aplay_thread�_supported_audio_backends�_requested_audio_backend�_audio_backend�os�path�isfile�LOGGER�info�access�R_OK�error�getattr)�selfrrs   �(/usr/share/ibus-table/engine/it_sound.py�__init__zSoundObject.__init__AsE��);�� �37���26���@D��!�EI�� �KO�� �,0������-1���>B���)c��&�(5��%� ����w�w�~�~�d�6�6�7��K�K�7�9K�L���y�y��1�1�2�7�7�;��K�K�5�7I�J���,�,��0N�0N�N��L�L�H�&��(F�(F�
H��U�g�d�f�T�5R�5R�4S�,T�U�W�������K�K�0�$�2E�2E�F��L�L�:�D�<Y�<Y�Zrc�\�|j�rytjjtjjtjj
fdkr|j
�ry|j�rytr�tjjtjjtjj
fdksBtjrCtd�tjjd�D��dk\r|j�ry	y
)Nr
)��rrr)r-�
rc3�2K�|]}t|����y�w�N)�int)�.0�xs  r*�	<genexpr>z.SoundObject._init_automatic.<locals>.<genexpr>}s����C�q�C��F�C�s��.)r�r.rr)�_init_pygame�sys�version_info�major�minor�micro�_init_simpleaudio�_init_aplay�IMPORT_PYAUDIO_SUCCESSFULr�__version__�tuple�split�
_init_pyaudio�r)s r*�_init_automaticzSoundObject._init_automaticas��������
�
�
�
#�
#�
�
�
�
#�
#�
�
�
�
#�
#�
%�'1�
2��%�%�'�$������

&����%�%����%�%����%�%�'�)3�4��!�!��C�G�$7�$7�$=�$=�c�$B�C�C�z�Q��!�!�#� �rc�x�tsy	tjj�tjj	�r4tjj
j
|j�y	y#t$r5}tjd|jj|�Yd}~yd}~wwxYw)Nrr
z%pygame: cannot load sound file %s: %s)
�IMPORT_PYGAME_MIXER_SUCCESSFULr
�mixer�init�get_init�music�loadr�	Exceptionr#�	exception�	__class__�__name__�r)r's  r*r8zSoundObject._init_pygame�s���-��	1��L�L�����|�|�$�$�&����"�"�'�'��(@�(@�A��'���	�	1����7����(�(�%�
1�
1���		1�s�A/A;�;	B9�+B4�4B9c�$�tsytj|j�\}}|dvr"tjd|j|�y	t
j|jd�|_tj�|_tj�|_tjdtj ��y#t"$r5}tj%d|j&j(|�Yd}~yd}~wwxYw)Nr�zaudio/x-wav�<File %s has mime type %s and is not supported by simpleaudio�rbzportaudio version = %srz'pyaudio: cannot init wave object %s: %s)r@�	mimetypes�
guess_typerr#r'�wave�openrr�PyAudior�	threading�Event�_stop_event_paudior$�get_portaudio_version_textrNrOrPrQ�r)�	mime_type�encodingr's    r*rDzSoundObject._init_pyaudio�s���(�� )� 4� 4�T�5M�5M� N���H��,�,��L�L�N��(�(�)�
5��
	1�!�Y�Y�t�'?�'?��F�D�N�"�?�?�,�D�L�7@���7H�D�#��K�K�0��:�:�<�
>����	1����9����(�(�%�
1�
1���		1�s�A?C�	D�+D
�
Dc��tsytj|j�\}}|dvr"tjd|j|�y	tjj|j�|_	y#t$r5}tjd|jj|�Yd}~yd}~wwxYw)NrrTrUr�.Initializing error sound object failed: %s: %s)�IMPORT_SIMPLEAUDIO_SUCCESSFULrWrXrr#r'r�
WaveObject�from_wave_filerrNrOrPrQr`s    r*r>zSoundObject._init_simpleaudio�s���,�� )� 4� 4�T�5M�5M� N���H��,�,��L�L�N��(�(�)�
5��	1��&�&�5�5�d�6N�6N�O�
�$� ���	1����@����(�(�%�
1�
1���		1�s�.B�	B>�	+B9�9B>c��tj|j�\}}|dvr"tj	d|j|�ytjd�|_|jsyt|jd��5}|j�|_
|jr
	ddd�y	ddd�y#1swYyxYw)NrTz6File %s has mime type %s and is not supported by aplayrrrV)�mode)rWrXrr#r'�shutil�whichrrZ�readr)r)rarb�aplay_inputs    r*r?zSoundObject._init_aplay�s��� )� 4� 4�T�5M�5M� N���H��,�,��L�L�H��(�(�)�
5��#�\�\�'�2����!�!��
�4�+�+�$�
7�	�;� +� 0� 0� 2�D��� � ��	�	� �	��		��s�#B=�=Cc��|jr|jj�|jr|jj�yyr1)r�	terminater�closerEs r*�__del__zSoundObject.__del__�s5���<�<��L�L�"�"�$��>�>��N�N� � �"�r�
stop_eventc�L�|js!tjd|j�y|jstjd�ytjd�|jj
|jj|jj��|jj�|jj�d��}d}|jj�|jj|�}|rv|j�sf	|j�stjd�n?|j|�|jj|�}|r|j�s�f|j+�|j-�tjd
�y#t t"f$rJ}tj%d|j&j(|�tjd	�Yd}~��d}~wwxYw)Nz!wave.open(%s, 'rb') did not work.zpyaudio.PyAudio() did not work.zPlaying sound with pyaudio ...T)�format�channels�rate�outputiz#pyaudio stream is_active() is Falsez+Unexpected error playing wave object %s: %sz�If 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.)rr#r'rrr$rZ�get_format_from_width�getsampwidth�getnchannels�getframerate�rewind�
readframes�is_set�	is_active�write�SystemError�OSErrorrOrPrQ�stop_streamrp)r)rr�stream�
chunk_size�datar's      r*�_play_pyaudio_thread_functionz)SoundObject._play_pyaudio_thread_function�s����~�~��L�L�>��1�1�
3���|�|��L�L�:�;�����4�5����"�"��<�<�5�5����+�+�-�/��^�^�0�0�2����,�,�.��#����
��������~�~�(�(��4���:�,�,�.�
��'�'�)��L�L�!F�G�����T�"��~�~�0�0��<��
�:�,�,�.�$	�����������6�7�� ��)�

�� � �A��O�O�,�,�e�5����P�Q���

�s�/%G
�,G
�
H#�AH�H#c���|jj�tjd|j|jf��|_|j
j
�y)NT)�daemon�target�args)r^�clearr\�Threadr�r�startrEs r*�
_play_pyaudiozSoundObject._play_pyaudio�sS�����%�%�'�$-�$4�$4���5�5��)�)�+�%-��!�	
�!�!�'�'�)rc�P�|jsy|jj�S�NF)r�is_aliverEs r*�_is_playing_pyaudiozSoundObject._is_playing_pyaudios#���(�(���(�(�1�1�3�3rc�&�|jsy|jj�rj|jj�sO|jj	�|jj�|jj
�yyyr1)rr�r^r~�set�joinr�rEs r*�
_stop_pyaudiozSoundObject._stop_pyaudiosr���(�(���%�%�.�.�0��+�+�2�2�4��#�#�'�'�)��%�%�*�*�,��#�#�)�)�+�5�
1rc��|jsy|jj�r|jj�yyr1)rr�r�rEs r*�_wait_done_pyaudiozSoundObject._wait_done_pyaudios7���(�(���$�$�-�-�/��%�%�*�*�,�0rc���|jsy	|jj�|_y#t$r5}tjd|jj|�Yd}~yd}~wwxYw)Nrd)r�playrrNr#rOrPrQrRs  r*�_play_simpleaudiozSoundObject._play_simpleaudios_���'�'��	1�'+�'?�'?�'D�'D�'F�D�$���	1����@����(�(�%�
1�
1��	1�s�/�	A-�+A(�(A-c�b�|jsyt|jj��Sr�)r�bool�
is_playingrEs r*�_is_playing_simpleaudioz#SoundObject._is_playing_simpleaudios(���'�'���D�,�,�7�7�9�:�:rc��|jsy|jj�|jj�yr1)r�stop�	wait_donerEs r*�_stop_simpleaudiozSoundObject._stop_simpleaudio#s4���'�'��� � �%�%�'�	
� � �*�*�,rc�R�|jsy|jj�yr1)rr�rEs r*�_wait_done_simpleaudioz"SoundObject._wait_done_simpleaudio+s ���'�'��� � �*�*�,rc��tjjj�tjjj	�yr1)r
rIrLr|r��rr*�_play_pygamezSoundObject._play_pygame0s.�������!�!�#��������!rc�R�tjjj�Sr1�r
rIrL�get_busyr�rr*�_is_playing_pygamezSoundObject._is_playing_pygame5s���|�|�!�!�*�*�,�,rc�T�tjjj�yr1)r
rIrLr�r�rr*�_stop_pygamezSoundObject._stop_pygame9s���������!rc��tjjj�r+	tjjj�r�*yyr1r�r�rr*�_wait_done_pygamezSoundObject._wait_done_pygame=s3���l�l� � �)�)�+���l�l� � �)�)�+rc
�0�|jsy	tjddtjtjtjddd��|_	|jj|jd��	|jj�y#t
tf$r5}tjd|jj|�Yd}~yd}~wwxYw#tj$rO}tjd|jj|�|jj�Yd}~yd}~wwxYw#t $r�}tjd|jj|�	tj#d	�|jj�tj#d
�nF#t $r5}tjd|jj|�Yd}~nd}~wwxYwYd}~yYd}~yd}~wwxYw)NrF)�shell�stdin�stderr�stdoutrb�errors�textz!cannot start aplay process %s: %si�)�input�timeoutz2timeout piping sound file into aplay process%s: %s�%cannot terminate aplay process %s: %s�Trying to kill aplay processzaplay process killed�cannot kill aplay process%s: %s)r�
subprocess�Popen�PIPErr��
ValueErrorr#rOrPrQ�communicater�TimeoutExpired�killrorNr$rRs  r*�_play_aplay_thread_functionz'SoundObject._play_aplay_thread_functionBs����!�!��	�",�"2�"2�7�%�9C���:D�/�/�:D�/�/�<@�:>�8<�
#>�D��	����+�+�$�2C�2C�48�
,�
:�
	5����)�)�+����$�	����3����(�(�%�
1�
��		���(�(�	����D����(�(�%�
1�
���$�$�&���	���	5����7����(�(�%�
1�
5����:�;��#�#�(�(�*����2�3���
5�� � �5��O�O�,�,�e�5�5��
5��5�4��	5�st�AB�'C&�E�C#�.+C�C#�&E�9AE�E�	H�+H�AG�H�	H�+G>�9H�>H�H�Hc��tjd|j��|_|jj	�y)NT)r�r�)r\r�r�rr�rEs r*�_play_aplayzSoundObject._play_aplayjs5��"+�"2�"2���3�3�#5���	
���%�%�'rc�P�|jsy|jj�Sr�)rr�rEs r*�_is_playing_aplayzSoundObject._is_playing_aplayps#���&�&���&�&�/�/�1�1rc�
�|jsy|jj�rA|jr5|jj��	|jj	�|jj�rM|jjd��|jj�rtjd�yyy#t
$r�}tjd|jj|�	tjd�|jj�nA#t
$r5}tjd|jj|�Yd}~nd}~wwxYwYd}~��d}~wwxYw)Nr�r�r�g�������?)r�ztimeout stopping aplay thread)rr�r�pollrorNr#rOrPrQr$r�r�r'rRs  r*�_stop_aplayzSoundObject._stop_aplayus4���&�&���#�#�,�,�.��#�#��#�#�(�(�*�2�
5��#�#�-�-�/��"�"�+�+�-��#�#�(�(��(�5��&�&�/�/�1����<�=�2�.���

5�� � �7����(�(�%�1�5��K�K� >�?��'�'�,�,�.�� �5��$�$�9��O�O�,�,�e�5�5��5���

5�sB�C�	F�+E=�/D6�5E=�6	E4�?+E/�*E=�/E4�4E=�=Fc��|jsy|jj�r|jj�yyr1)rr�r�rEs r*�_wait_done_aplayzSoundObject._wait_done_aplay�s7���&�&���"�"�+�+�-��#�#�(�(�*�.rc��|js!tjd|j�yt	|d|j����y)zPlay the sound�#Could not init any audio backend %sN�_play_�rr#r'rr(rEs r*r�zSoundObject.play��C���"�"��L�L�>��6�6�
8��5����t�2�2�3�4�5�7rc��|js!tjd|j�yt	t|d|j�����S)z,Check whether the sound is currently playingr�F�_is_playing_)rr#r'rr�r(rEs r*r�zSoundObject.is_playing�sL���"�"��L�L�>��6�6�
8���G�G�D�L��1D�1D�0E�"F�G�I�J�Jrc��|js!tjd|j�yt	|d|j����y)zStop playing of the soundr�N�_stop_r�rEs r*r�zSoundObject.stop�r�rc��|js!tjd|j�yt	|d|j����y)z*Wait until the sound has been fully playedr�N�_wait_done_r�rEs r*r�zSoundObject.wait_done�sC���"�"��L�L�>��6�6�
8��:����D�$7�$7�#8�9�:�<r)r�r	N)&rQ�
__module__�__qualname__�__doc__�strr+rFr8rDr>r?rqr\r]r�r�r�r�r�r�r�r�r�r��staticmethodr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr*rr:sS���'2�[�%(�[� #�[�6:�[�@ �� �D�c���s��,�3��&�S�� #�&8�	���&8�D�&8�P*�4�T�4�
,�-�1�;��;�
-�-�
�"��"��-��-��-��"��"�����&5�P(�2�4�2�
>�0+�8�K�D�K�8�=rrc��d}td|��}|j�|j�|j�|j�ddl}td|��}|j�tjd�|j
d�tjd	|j��|j�tjd	|j��|j
d
�y)zRun some simple testsrz$/usr/share/ibus-table/data/coin9.wav)rrNuI/home/mfabian/sounds/japanese/今回もよろしくお願いします.wavzSleeping ...�z
is playing %s�)	rr�r��timer#r$�sleepr�r�)r�sound_objectr�s   r*�	run_testsr��s��� �M��.�#�	%�L�
������������������S�#�%�L�����
�K�K����J�J�q�M�
�K�K���!8�!8�!:�;�����
�K�K���!8�!8�!:�;��J�J�q�Mr�__main__)r�r�)r��typingrrr9r �loggingr\rYrjr�rW�	getLoggerr#rH�pygame.mixerr
�ImportErrorr@rrerrr�rQ�
StreamHandlerr��LOG_HANDLER�setLevel�DEBUG�
addHandlerr�rr*�<module>r�s ��(���
�	����
���	��	�	�<�	(��!&��+��%)�"�"��&�� $��!&��*��$(�!�w=�w=�r�<�z��'�'�'�'�s�z�z�:�K�
�O�O�G�M�M�"�
���k�"�
�K���Q
	�~�+�%*�"�+��	�~�&� %��&��	�~�*�$)�!�*�s6�C�
C�C�C�C�C�C�C(�'C(

Zerion Mini Shell 1.0