o
    㥵iH                     @   sR   d dl mZ d dlZd dlmZ d dlmZ d dlm	Z	 dZ
de	defd	d
ZdS )    )
HTTPStatusN)HTTPException)TTSInferenceEngine)ServeTTSRequesti   reqenginec                 c   s    d}| | D ]Y}|j dkr t|jtr|jd V  q dkr- ttjt|j	d dkrK |d7 }t|jtrJ|jd t
 tj V  qdkra|d7 }t|jtr^|jd V   dS q|dkrmttjd	ddS )
zI
    Wrapper for the inference function.
    Used in the API server.
    r   header   error)contentsegmentfinalNz0No audio generated, please check the input text.)	inferencecode
isinstanceaudiotupler   r   INTERNAL_SERVER_ERRORstrr
   	AMPLITUDEastypenpint16tobytes)r   r   countresult r   J/home/ubuntu/.local/lib/python3.10/site-packages/tools/server/inference.pyinference_wrapper   s<   


r   )httpr   numpyr   kui.asgir   fish_speech.inference_enginer   fish_speech.utils.schemar   r   r   r   r   r   r   <module>   s    