U
    =?]                     @   st   d dl Z d dlZd dlmZmZmZmZmZmZ d dlZd dl	Z	d dl
Z
e ZdZddddZedd	d
 ZdS )    N)Jinja2Templatejinja2_viewstatic_fileresponseBottlerequestz*https://www.ispeech.org/p/generic/getaudioconvertZ1000)actionZpitchZspeedz/ttsc               	   C   s   t jd } t jd }t }| |d< ||d< tjt|d}|j}d}tj	dd}|
| |j}W 5 Q R X t|}t|d d	 d
 }tj||d djddddjdd\}	}
dt_t| |	S )NtextlocaleZvoice)params F)deletestreamsr   Zduration   )tzpipe:Zmp3Z320k)formatZaudio_bitrateT)Zcapture_stdoutz
audio/mpeg)r   query	BASE_ARGScopyrequestsgetBASE_URLcontenttempfileNamedTemporaryFilewritenameffmpegZprobefloatinputoutputrunr   content_typeosunlink)r   r   argsrespZ	mpeg_dataZtemp_filenamefZfdataZdurZcut_ r+   /opt/wsgi/tts/tts.py	proxy_tts   s"    



*
r-   )r   bottler   r   r   r   r   r   r   r   r%   appr   r   router-   r+   r+   r+   r,   <module>   s    