U
    ,:%e	                     @   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ejj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   s2  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rtd
| j
 d|  \}}|d	krtd| d tjj||d}|j|||d d}	| 8 td||	D ]$}
|d| |
|
|	 ddf  qW 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.)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"   V/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torchaudio/io/_playback.py
play_audio   s.    




r$   )N)r   sysr   typingr   Ztorchr   Zuint8Zint16Zint32Zint64Zfloat32Zfloat64r   
_extensionZfail_if_no_ffmpegZTensorfloatstrr$   r"   r"   r"   r#   <module>   s2         
 