+
    Pj4                     ^  a  R, t?0 t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
 ^ RIt^ RIt^ RIHtHtHtHtHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ R	IHtHtHtH t H!t!H"t"H#t#H$t$ ^ R
I%H&t&H't' ^ RI(H)t) ^ RI*H+t+ ]PX                  ! ]-4      t.]P^                  ! RRR7      t0Rs1] ^ k ]! RRRR7      t2]2Pg                  ]. R-ORR.R.R7       ]2Pi                  R]R7      R 4       t5]2Pi                  R4      R 4       t6R t7R R lt8]2Ps                  R4      ]! R 4      ]! R4      ]! R4      3R! R" ll4       t:]0Pw                  4       R.R# R$ ll4       t<]0Pw                  4       RRRRR]]!] ]]R%R&]"R3R' R( ll4       t=]0Pw                  4       R/R) R* ll4       t>]-R+8X  d
   ]0! 4        R# R# )0    N)Path)Queue)FastAPIFileFormHTTPException
UploadFile)CORSMiddleware)HTMLResponseStreamingResponse)	Annotated)stream_audio_chunks)DEFAULT_EOS_THRESHOLDDEFAULT_FRAMES_AFTER_EOSDEFAULT_LSD_DECODE_STEPSDEFAULT_NOISE_CLAMPDEFAULT_TEMPERATUREMAX_TOKEN_PER_CHUNKget_default_text_for_languageget_default_voice_for_language)TTSModelexport_model_state)enable_logging)_ORIGINS_OF_PREDEFINED_VOICESz2Kyutai Pocket TTS - Text-to-Speech generation toolF)helppretty_exceptions_show_localszKyutai Pocket TTS APIzText-to-Speech generation APIz1.0.0)titledescriptionversionT*)allow_originsallow_credentialsallow_methodsallow_headers/)response_classc                 $  "   \        \        4      P                  R,          R,          p V P                  4       p\	        \        \        P                  4      4       VP                  R\        \        \        P                  4      4      4      pV# 5i)zServe the frontend.staticz
index.htmlDEFAULT_TEXT_PROMPT)
r   __file__parent	read_textprintstr	tts_modeloriginreplacer   )static_pathcontents     h/Users/ahmed/devFolder/Ultron/claude-voice/gateway/.venv/lib/python3.14/site-packages/pocket_tts/main.pyrootr5   >   sl      x.''(2\AK##%G	#i
 oo<SAQAQ=RSG Ns   BBz/healthc                     "   R R/# 5i)statushealthy r9       r4   healthr;   K   s     i  s   c                     ! R R\         P                  4      p\        P                  W!R7      p\	        V! V 4      V\        P
                  P                  P                  4       R# )z=Allows writing to the StreamingResponse as if it were a file.c                   8   a  ] tR t^St o R tR tR tR tRtV t	R# )'write_to_queue.<locals>.FileLikeToQueuec                    Wn         R # Nqueue)selfrB   s   &&r4   __init__0write_to_queue.<locals>.FileLikeToQueue.__init__T   s    Jr:   c                <    V P                   P                  V4       R # r@   rB   put)rC   datas   &&r4   write-write_to_queue.<locals>.FileLikeToQueue.writeW       JJNN4 r:   c                    R # r@   r9   rC   s   &r4   flush-write_to_queue.<locals>.FileLikeToQueue.flushZ   s    r:   c                <    V P                   P                  R 4       R # r@   rG   rN   s   &r4   close-write_to_queue.<locals>.FileLikeToQueue.close]   rL   r:   rA   N)
__name__
__module____qualname____firstlineno__rD   rJ   rO   rR   __static_attributes____classdictcell__)__classdict__s   @r4   FileLikeToQueuer>   S   s     		!		! 	!r:   r[   )model_statetext_to_generateN)ioIOBaser/   generate_audio_streamr   configmimisample_rate)rB   r]   r\   r[   audio_chunkss   &&&  r4   write_to_queuere   P   sQ    !")) ! 22 3 L .i>N>N>S>S>_>_`r:   c                0    V ^8  d   QhR\         R\        /# )   r]   r\   )r.   dict)formats   "r4   __annotate__rj   f   s      s  r:   c              #      "   \        4       p\        P                  ! \        W V3R 7      pVP	                  4        ^ p VP                  4       pVf   MV^,          pVx  K%  VP                  4        R# 5i))targetargsN)r   	threadingThreadre   startgetjoin)r]   r\   rB   threadirI   s   &&    r4   generate_data_with_stateru   f   sc     GE ^5T_:`aF
LLN 	
A
yy{<	Q

KKMs   A2A4z/tts.c                X    V ^8  d   QhR\         R\         R,          R\        R,          /# )rg   text	voice_urlN	voice_wav)r.   r	   )ri   s   "r4   rj   rj   z   s/     ; ;
;Tz; D ;r:   c                L   V P                  4       '       g   \        RRR7      hVf'   Vf#   \        \        \        P
                  4      4      pVe   Ve   \        RRR7      hVe   VP                  R4      '       gG   VP                  R4      '       g0   VP                  R4      '       g   V\        9   g   \        RR	R7      h\        P                  V4      p\        P                  ! R
V4       MVe   VP                  '       d    \        VP                  4      P                  MRp\        P                  ! RVR7      ;_uu_ 4       pVP                   P#                  4       pVP%                  V4       VP'                  4        VP(                  pRRR4        \        P+                  \        X4      RR7      p\,        P.                  ! V4       M\        RRR7      h\1        \3        W4      RRRRR/R7      #   + '       g   i     Lp; i  \,        P.                  ! X4       i ; i)a2  
Generate speech from text using the pre-loaded voice prompt or a custom voice.

Args:
    text: Text to convert to speech
    voice_url: Optional built-in voice name (e.g., "alba"), or voice URL (http://, https://, or hf://)
    voice_wav: Optional uploaded voice file (mutually exclusive with voice_url)
i  zText cannot be empty)status_codedetailNz+Cannot provide both voice_url and voice_wavzhttp://zhttps://zhf://z5voice_url must start with http://, https://, or hf://zUsing voice from URL: %sz.wavF)deletesuffixT)truncatei  zThis should never happen.z	audio/wavzContent-Dispositionz)attachment; filename=generated_speech.wavzTransfer-Encodingchunked)
media_typeheaders)stripr   r   r.   r/   r0   
startswithr   "_cached_get_state_for_audio_promptloggingwarningfilenamer   r~   tempfileNamedTemporaryFilefilereadrJ   rO   nameget_state_for_audio_promptosunlinkr   ru   )rw   rx   ry   r\   r~   	temp_filer3   temp_file_paths   &&&     r4   text_to_speechr   y   s    ::<<4JKKY.23y7G7G3HI	!64abb   ++##J//##G,,99(_   BB9M2I>		4=4F4F4Fi(()00F((fEEnn))+GOOG$OO&^^N	 F	&#>>tN?S^b>cKIIn%4OPP 3!#N
  FE IIn%s   AG8 H 8H	H#c                   V ^8  d   QhR\         \        \        P                  ! RR7      3,          R\         \        \        P                  ! RR7      3,          R\         \
        \        P                  ! RR7      3,          R\         \        R	,          \        P                  ! R
RR7      3,          R\         \        R	,          \        P                  ! RR7      3,          R\         \
        \        P                  ! RR7      3,          /# )rg   hostzHost to bind tor   portzPort to bind toreloadzEnable auto-reloadlanguageNzLanguage for the TTS model. 'english_2026-01', 'english_2026-04', 'english', 'french_24l', 'german_24l', 'portuguese', 'italian', 'spanish'. Incompatible with the config argument. Default is 'english', which is the same model as 'english_2026-04'.Fr   show_defaultra   Path to locally-saved model config .yaml file. Incompatible with the language argument. If not provided, will use the default English model.quantize.Apply int8 quantization to reduce memory usage)r   r.   typerOptionintbool)ri   s   "r4   rj   rj      s     P P
C+<==
>P
C+<==
>P dELL.BCCDP d
z 		
		P d
l	
	P( ell PQQ)Pr:   c                h    \         P                  ! W4VR7      s\        P                  ! RWVR7       R# )zStart the FastAPI server.)r   ra   r   zpocket_tts.main:web_app)r   r   r   N)r   
load_modelr/   uvicornrun)r   r   r   r   ra   r   s   &&&&&&r4   server      s'    8 ##XxXIKK)Or:   z./tts_output.wavcpuc          !         V ^8  d   QhR\         \        \        P                  ! RR7      3,          R\         \        R,          \        P                  ! RRR7      3,          R	\         \        \        P                  ! R
RRR7      3,          R\         \        R,          \        P                  ! RRR7      3,          R\         \        R,          \        P                  ! RR7      3,          R\         \
        \        P                  ! RR7      3,          R\         \        \        P                  ! RR7      3,          R\         \        \        P                  ! RR7      3,          R\         \        \        P                  ! RR7      3,          R\         \
        \        P                  ! RR7      3,          R\         \        \        P                  ! RR7      3,          R\         \        \        P                  ! RR7      3,          R\         \
        \        P                  ! R R7      3,          R!\         \        \        P                  ! R"R7      3,          /# )#rg   rw   zText to generater   voiceNzPath to audio conditioning file (voice to clone). Defaults to a built-in voice chosen from the language: 'giovanni' for italian, 'lola' for spanish, 'juergen' for german, 'rafael' for portuguese, 'estelle' for french, 'alba' otherwise.Fr   quiet-q--quietDisable logging outputr   a  Language for the TTS model. 'english_2026-01', 'english_2026-04', 'english', 'french_24l', 'spanish_24l','german_24l', 'portuguese_24l', 'italian_24l'. Incompatible with the config argument. Default is 'english', which is the same model as 'english_2026-04'. The '24l' variants are bigger models, not distilled yet and here only as preview. They're not the final models for those languages.ra   r   lsd_decode_stepszNumber of generation stepstemperaturezTemperature for generationnoise_clampzNoise clamp valueeos_thresholdzEOS thresholdframes_after_eosz&Number of frames to generate after EOSoutput_pathzOutput path for generated audiodevicezDevice to use
max_tokensz#Maximum number of tokens per chunk.r   r   )r   r.   r   r   r   r   float)ri   s   "r4   rj   rj      s    h
 h

C+=>>
?h
d
S
 	
		h
 T5<<i>VWWXh
 d
. 	
	h
< d
l	
	=h
J  U\\;<<Kh
P u||!=>>Qh
V 5%,,4G"HHIWh
X UELLo$FFGYh
Z  U\\GHH[h
` U\\@AAah
f c5<<_==>gh
h U\\DEEih
n ell PQQoh
r:   c                x   V'       d   \         P                  M\         P                  p\        RV4      ;_uu_ 4        V f   \	        V4      p V R8X  d   \
        P                  P                  4       p V P                  4       '       g-   \        P                  R4       \        P                  ! ^R7      h\        P                  ! VVVVVVVR7      pVP                  V4       Vf   \!        V4      pVP#                  V4      pVP%                  VV V	VR7      p\'        V
VVP(                  P*                  P,                  4       V
R8w  d   \        P/                  RV
4       \        P/                  R4       \        P/                  R	4       \        P/                  R
4       RRR4       R#   + '       g   i     R# ; i)z(Generate speech using Kyutai Pocket TTS.
pocket_ttsN-zNo input received from stdin.)code)r   ra   tempr   r   r   r   )r\   r]   r   r   zResults written in %szPIf you want to try multiple voices and prompts quickly, try the `serve` command.zRIf you like Kyutai projects, comment, like, subscribe at https://x.com/kyutai_labsz--------------------)r   ERRORINFOr   r   sysstdinr   r   loggererrorr   Exitr   r   tor   r   r`   r   ra   rb   rc   info)rw   r   r   r   ra   r   r   r   r   r   r   r   r   r   	log_levelr/   model_state_for_voicerd   s   &&&&&&&&&&&&&&    r4   generater      sY   z "'GLLI	i	0	0<0:D3;99>>#Dzz||LL89**!$$''-#'
	 	V=28<E ) D DU K 66-!-!	 7 
 	Ky7G7G7L7L7X7XY #KK/=H^	
 	`	
S 
1	0	0	0s   A
F(DF((F9	c                   V ^8  d   QhR\         \        \        P                  ! RR7      3,          R\         \        \        P                  ! RR7      3,          R\         \        \        P
                  ! RRR	R7      3,          R
\         \        R,          \        P
                  ! RRR7      3,          R\         \        R,          \        P
                  ! RR7      3,          /# )rg   
audio_pathz-Audio file or directory to convert and exportr   export_pathzOutput file or directoryr   r   r   r   r   NaT  Language for the TTS model. 'english_2026-01', 'english_2026-04', 'english', 'french_24l', 'german_24l','spanish_24l', 'portuguese_24l', 'italian_24l'. Incompatible with the config argument. Default is 'english', which is the same model as 'english_2026-04'. The '24l' variants are bigger models, not distilled yet and here only as preview.Fr   ra   r   )r   r.   r   Argumentr   r   )ri   s   "r4   rj   rj   P  s     $5 $5U^^!PQQ$5 34N OOP	$5
 T5<<i>VWWX$5 d
> 
	
	$5( d
l	
	)$5r:   c                "   V'       d   \         P                  M\         P                  p\        RV4      ;_uu_ 4        \        P
                  ! W4R7      pVP                  V RR7      p\        Wq4       RRR4       R#   + '       g   i     R# ; i)z+Convert and save audio to .safetensors filer   )r   ra   T)audio_conditioningr   N)r   r   r   r   r   r   r   r   )r   r   r   r   ra   r   r/   r\   s   &&&&&   r4   export_voicer   O  se    > "'GLLI	i	0	0''I	::)D ; 
 	;4 
1	0	0	0s   6A==B	__main__c                N    V ^8  d   Qh/ ^ \         9   d   \        R,          ;R&   # )rg   Nr/   )__conditional_annotations__r   )ri   s   "r4   rj   rj      s    		V " !8d? !W 
r:   )zhttp://localhost:3000z&https://pod1-10007.internal.kyutai.orgzhttps://kyutai.org)	localhosti@  FNNF)FNN)@r   r^   r   r   r   r   rn   pathlibr   rB   r   r   r   fastapir   r   r   r   r	   fastapi.middleware.corsr
   fastapi.responsesr   r   typing_extensionsr   pocket_tts.data.audior   pocket_tts.default_parametersr   r   r   r   r   r   r   r   pocket_tts.models.tts_modelr   r   pocket_tts.utils.logging_utilsr   pocket_tts.utils.utilsr   	getLoggerrT   r   Typercli_appr/   web_appadd_middlewarerq   r5   r;   re   ru   postr   commandr   r   r   rj   )r   s   @r4   <module>r      s   		  	 
       B B 2 = ' 5	 	 	 E 9 @			8	$
++	=]b "	 !

!/NX_   
 %%  
 	S.	 /	 	Y! !a,& 	fS	 J#':; ;| 	P PJ 	BF 	[` 	 	 	! 	L_J_ 	! 	AF 	 	sh
 h
` 	$5 $5N zI r:   