U
    CŒÑh	  ã                   @   s|   d dl Z d dlmZ d dlmZ d dlZd dlZejdejdej	dej
dejdejd	iZdejee ee dd
œdd„ZdS )é    N)Úplatform)ÚOptionalÚu8Zs16Zs32Zs64ZfltZdbl)ÚwaveformÚsample_rateÚdeviceÚreturnc              	   C   s8  t dkr|pd}d}ntdt › �ƒ‚ttjj ¡  ¡ ƒ}||krTtd|› d|› �ƒ‚| jt	krxtd| j› dt	 ¡ › �ƒ‚t	| j }| j
d	kržtd
| j
› d�ƒ‚|  ¡ \}}|d	krÈtjd|› d�d	d� tjj||d�}|j|||d� d}	| ¡ �: td||	ƒD ]&}
| d| |
|
|	 …dd…f ¡ �qW 5 Q R X dS )a  Plays audio through specified or available output device.

    .. warning::
       This function is currently only supported on MacOS, and requires
       libavdevice (FFmpeg) with ``audiotoolbox`` output device.

    .. note::
       This function can play up to two audio channels.

    Args:
        waveform: Tensor containing the audio to play.
            Expected shape: `(time, num_channels)`.
        sample_rate: Sample rate of the audio to play.
        device: Output device to use. If None, the default device is used.
    ÚdarwinZaudiotoolboxú-z5This function only supports MacOS, but current OS is zDevice z* is not available. Available devices are: zUnsupported type z". The list of supported types is: é   z:Expected 2D tensor with shape `(time, num_channels)`, got zD tensor insteadzExpected up to 2 channels, got z< channels instead. Only the first 2 channels will be played.)Ú
stacklevel)ÚdstÚformat)r   é   r   N)r   Ú
ValueErrorÚlistÚ
torchaudioÚutilsZffmpeg_utilsZget_output_devicesÚkeysZdtypeÚdict_formatÚndimÚsizeÚwarningsÚwarnÚioÚStreamWriterZadd_audio_streamÚopenÚrangeZwrite_audio_chunk)r   r   r   ÚpathZavailable_devicesr   ÚtimeZnum_channelsÚsÚ
block_sizeÚi© r#   úE/tmp/user/2202/pip-unpacked-wheel-p89lpdx5/torchaudio/io/_playback.pyÚ
play_audio   s0    



ý
r%   )N)r   Úsysr   Útypingr   Ztorchr   Zuint8Zint16Zint32Zint64Zfloat32Zfloat64r   ZTensorÚfloatÚstrr%   r#   r#   r#   r$   Ú<module>   s0         ú ýü