
    
`j0                     6   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
m
Z
mZ d dlmZ  ee                                          j        d         Zedz  Zedz  Zedz  Zedz  Zed	z  Zed
z  Zedz  Zedz  Zedz  Zedz  Zedz  Zedz  Zedz  Zedz  ZdZ dZ!dZ"d Z#d Z$d Z%d"dZ&d Z'd Z(d Z)d Z*e+dk    rS	  ej,         e*                       dS # e-$ r0Z. e/d e. ej0        !            ej,        d           Y dZ.[.dS dZ.[.ww xY wdS )#    N)datetimetimezone)Path   zstory/promotion.jsonzimage/layout-manifest-r2.jsonz$image/intro-poster-1920x1080-r2.jsonz#script/workflow-copy-authority.jsonz#image/intro-poster-1920x1080-r2.pngzaudio/intro-voice-source.txtz#audio/intro-voice-pronunciation.txtz log/intro-tts-pronunciation.jsonz!script/pronunciation-lexicon.jsonzaudio/intro-voice.wavzaudio/intro-full.wavzoutput/intro/intro.mp4zlog/intro-render.jsonzlog/intro-voice.jsonzhttp://192.168.40.33:7862zhttp://192.168.1.104:8021zngoc-huyen-vbeec                    t          j                    }|                     d          5 t          fdd          D ]}|                    |           	 d d d            n# 1 swxY w Y   |                                S )Nrbc                  .                          d          S )Ni   )read)handles   /data/video-pipeline/Chanel-HuyenAnAudio/project/016-Ngay-Chung-Toi-Nop-Don-Ly-Hon-Anh-Dua-Toi-Ban-Hon-Uoc-Khong-Con-Dieu-Khoan-Nao/script/render-intro-gpu.py<lambda>zsha.<locals>.<lambda>%   s    &++o">">     r   )hashlibsha256openiterupdate	hexdigest)pathdigestblockr   s      @r   shar   "   s    ^F	4 !F>>>>DD 	! 	!EMM%    	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! s   ,A##A'*A'c                     t          j        dddddddddt          |           g
d	d	d	
          }t          j        |j                  S )Nffprobez-verrorz-show_entrieszformat=duration,sizezMstream=index,codec_name,width,height,sample_rate,channels:stream_tags=encoderz-ofjsonT)capture_outputtextcheck)
subprocessrunstrr   loadsstdout)r   results     r   prober&   *   sY    ^4/3Ihvs4yy T	3 3 3F
 :fm$$$r   c           	         t          j        t          |           d          5 }|                                |                                |                                |                                |                                |                                |                                z  dcd d d            S # 1 swxY w Y   d S )Nr   )channelssample_widthsample_rateframescompressionduration_seconds)waver   r"   getnchannelsgetsampwidthgetframerate
getnframesgetcomptype)r   r   s     r   wav_infor4   3   s    	3t99d	#	# 
v++--"//11!..00''))!--// & 1 1 3 3f6I6I6K6K K
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   B
B::B>B>   c                 P   |'t          j        |                              d          nd }t          j                            | ||rddini |rdnd          }t          j                            ||          5 }t          j        |          cd d d            S # 1 swxY w Y   d S )Nutf-8Content-Typezapplication/jsonPOSTGETdataheadersmethodtimeout)r   dumpsencodeurllibrequestRequesturlopenload)urlpayloadr@   bodyrD   responses         r   request_jsonrL   ?   s	   292E4:g%%g...4Dn$$Stei=qnN`=a=aoq  EI  {T  {A  {A  OT$  U  UG					9	9 #Xy""# # # # # # # # # # # # # # # # # #s   :BB"Bc                    t          j        t                              d                    }|                    d          dus|                    d          dk    rt          d          |                    d          | k    |                    d	          t          t                    k    |                    d
          t          t                    k    |                    d          t          t                    k    |                    d          du |                    d          dk    |                    d          du |                    di                               di                               dd          dk    |                    d           f	}|                    di                               di                               dd          }t          |          r|dk     rt          d          |S )Nr7   encodingverifiedTkindintroz#intro pronunciation receipt invalidsource_canon_sha256source_sha256projection_sha256lexicon_sha256reverse_verifiednon_lexicon_changesr   semantic_content_changedFcountsaudioreplacement_countr   unresolved_requiredu2   intro audio -> au đi ô pronunciation gate failed)r   r#   PRONUNCIATION	read_textgetRuntimeErrorr   SOURCE
PROJECTIONLEXICONall)canonpronunciationchecksaudio_counts       r   validate_pronunciationrj   F   s   J}666HHIIM$$D00M4E4Ef4M4MQX4X4X@AAA/00E9/**c&kk9-..#j//A*++s7||;,--5/00A5455>(B''++GR88<<=PRSTTXYY3444
F  ##Hb1155grBBFFGZ\]^^Kv;; Q+//OPPPr   c                 
   t          t                    }t          t                    }t                                          rt
                                          rt          j        t                              d                    }|	                    d          du r|	                    d          | k    r|	                    d          t          t                    k    r}|	                    d          |k    rd|	                    d          |k    rK|	                    d	          t          k    r-|	                    d
          t          t
                    k    r|S t          t          dz             }t          t          dz             	                    dg           }t          d |D             d           }|	                    d          dk    s0|r.|	                    d          dus|	                    d          durt          d          t                              d          }t           j                            |t          d                              d          }	t           j                            t          dz   |	ddid          }
t           j                            |
d          5 }|                                }d d d            n# 1 swxY w Y   t1          |          dk     s|d d         dk    s|dd          d!k    rt          d"          t
          j                            dd#           t
                              d$          }|                    |           t;          |          }|d%         d&k    s|d'         d(k    r%|                    d)           t          d*          t?          j         |t
                     i d+d,ddd| d-tC          t          "                    tF                              dt          t                    d.tC          t          "                    tF                              d|d/tC          t          "                    tF                              d|d0dd1t          tH                    d	t          d2t          d3tC          t
          "                    tF                              d
t          t
                    d4tK          t
                    d5|d6tM          j'        tP          j)                  *                                i}t          +                    t          j,        |d7d89          d:z   d           |S );Nr7   rN   rP   TrS   rT   rU   pronunciation_receipt_sha256voiceoutput_sha256/healthz/voicesvoicesc              3   V   K   | ]$}|                     d           t          k     |V  %dS )idN)r`   
VOICE_NAME).0items     r   	<genexpr>z#synthesize_intro.<locals>.<genexpr>g   s6      HH488D>>Z+G+G+G+G+G+GHHr   statusokmodel_existsconfig_existszintro TTS preflight failed)r   rm   z/ttsr8   z!application/x-www-form-urlencodedr9   r;   i,  r?   ,      s   RIFF      s   WAVEzintro TTS response is not WAVparentsexist_ok	.part.wavr-   r   r,   NONE)
missing_okz+intro TTS WAV technical verification failedversionr   source_pathprojection_pathpronunciation_receiptpronunciation_verifiedpronunciation_lexicon_sha256endpointoutputr&   wav
checked_atF   ensure_asciiindent
)-r   rc   r^   VOICE_RECEIPTexistsVOICEr   r#   r_   r`   rb   rs   rL   TTS_BASEnextra   rC   parse	urlencoderB   rD   rE   rF   r
   lenparentmkdirwith_suffixwrite_bytesr4   unlinkosreplacer"   relative_toPROJECTrd   r&   r   nowr   utc	isoformat
write_textrA   )rf   rg   projection_shareceipt_shaoldhealthrp   rowr   rJ   reqrK   r<   tempinforeceipts                   r   synthesize_intror   [   s3   __Nm$$K %,,.. j00'0BBCCGGJ4''CGG4I,J,Je,S,SGGO,,F;;H[@\@\`n@n@nGG:;;{JJswwW^O_O_cmOmOmGGO,,E

::J(Y.//F(Y.//33HbAAF
HHHHH$
O
OCzz(t##3##''.2I2IQU2U2UY\Y`Y`apYqYqy}Y}Y}788811D<!!4*"E"EFFMMgVVD
.
 
 F!2X{G|  FL
   M  MC			S		1	1 X}}              
4yy2~~bqbW,,QrT
g0E0E:;;;	Ltd333[))DTD>>D1$$](;v(E(Et$$$HIIIJtU
1
 $
(=u
s6--g6677
9H#f++
 	3z55g>>??
 BUVd
 	 ]%>%>w%G%G!H!H	

 	'

 6Nt
 	'G
 	
 (
 	#e''0011
 4CCJJ
 	u
  %d
 -9(,x|:T:T:^:^:`:`
 
G TZeANNNQUU`ghhhNs   9KK!Kc                 n   |                      d          t          t                    k    rt          d          t                              d          }t          j        t          t                    d          5 }|	                                }|
                                dk    rt          d          |                    |                                          }d d d            n# 1 swxY w Y   t          |j        dz            }d|z  |j        z  |j        z  }t          j        t          |          d	          5 }|                    |           |                    |           |                    |           d d d            n# 1 swxY w Y   t'          j        |t                     d S )
Nrn   z#intro voice receipt/output mismatchr   r   r   zintro voice WAV is compressedg       @    wb)r`   r   r   ra   FULLr   r.   r   r"   	getparamsr3   
readframesr2   int	framerate	nchannels	sampwidth	setparamswriteframesr   r   )voice_receiptr   sourceparamsr+   silence_framessilencetargets           r   append_silencer      s   ))SZZ77@AAAK((D	3u::t	$	$ 8!!##6))>???""6#4#4#6#677	8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
 )C/00N&)99F<LLG	3t99d	#	# $v   6"""7###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ JtTs&   <A#C++C/2C/A FFFc                  ^   t           t          t          t          t          t
          t          t          t          f	D ](} | 	                                st          d|            )t          j        t                               d                    }t          j        t                              d                    }|                    d          }|                    d          dus[|                    d          dusD|                    di                               d          dus|                    d          |k    rt          d	          t          j        t                              d                    }|                    d          du r|                    d
          dk    rj|                    di                               d          t          t                    k    r+|                    d          t          t                    k    st          d          t!          |           t"          t$          t&          fD ](} | 	                                st          d|            )t          j        t&                              d                    }|                    d          du r|                    d
          dk    r|                    d          |k    r|                    d          t          t
                    k    r|                    d          t          t                    k    rV|                    d          t          t"                    k    r+|                    d          t          t$                    k    st          d          t)          t+          t$                    d         d                   }t-          t.          dz             }|                    d
          dk    s0|                    d          dk    s|                    d          durt          d          t0                                          r_t4                                          rEt          j        t0                              d                    }|                    d          du r |                    d          |k    r|                    d          t          t                    k    r|                    d          t          t$                    k    r|                    d           t          t                    k    rf|                    d          t          t4                    k    r;t7          t          j        ddt;          t4                    d!d"#                     d$S t4          j                            dd%           d&tA          j!                    j"        d d'         z   }	i d(|	d)t;          t                    |d*gd+t;          t$                    d,d d-t;          t4                    d.d/d0d1d2d3d4d5d6d7d8d"d9d"d:d;d<d=d>d?d@d?dAd?d"d"dB}
t-          t.          dCz   |
dDE          }t4          	                                st          dF          t+          t4                    }|                    dGg           }t)          |d         d                   }tG          |          dHk    oGtI          dI |D                       o.tI          dJ |D                       otK          ||z
            dKk    }i dLdMd|d
|rdndNd|dt          t                    dOt          t                    d(|	dPt.          dQddR|dS|dt          t                    dt          t$                    dTt          t
                    d t          t                    dUt          t                    dVt          t&                    t;          t4          &                    tN                              t          t4                    ||ddWddXt          t                    dYtQ          j)        tT          j+                  ,                                dZ}t0          j                            dd%           t0          -                    t          j        |d"dH[          d\z   d           t7          t          j        ||	|d]d"#                     |rd$ndMS )^Nzmissing r7   rN   spoken_narration_sha256rP   T	visual_qarS   zintro authority gate mismatchrw   	completedr   r   workflow_copy_authority_sha256z-intro poster derivative receipt/hash mismatchz+terminal intro voice prerequisite missing: rT   rU   rn   full_output_sha256z*intro voice terminal receipt/hash mismatchformatdurationro   rx   encoder
h264_nvencnvenc_availablez-intro GPU endpoint does not verify h264_nvencposter_sha256audio_sha256intro_pronunciation_sha256)rP   reusedr   F)r   r   r   zhuyenan-016-intro-r~   job_idscenes)
image_pathr   
audio_pathsubtitle_pathoutput_pathwidthi  heighti8  fpsr5   crf   presetp4burn_subtitles	ken_burnsmotion_presetnone
transitioncuttransition_durationg        fade_infade_out)slice_audioslice_subtitlesz/stickman-render-gpui  r?   z*intro GPU endpoint returned without outputstreamsr   c              3   H   K   | ]}|                     d           dk    V  dS )
codec_nameh264Nr`   rt   r   s     r   rv   zmain.<locals>.<genexpr>   s3      (\(\S)>)>&)H(\(\(\(\(\(\r   c              3   H   K   | ]}|                     d           dk    V  dS )r   aacNr   r   s     r   rv   zmain.<locals>.<genexpr>   se        eX  eX  ILehelelmyezez  D  fD  eX  eX  eX  eX  eX  eXr   g?r   r   failed poster_derivative_receipt_sha256r   encoder_requiredserver_healthserver_resultintro_source_sha256"intro_pronunciation_receipt_sha256intro_voice_receipt_sha256passed_via_static_posterzHimage/layout-manifest-r2.json visual_qa; no intro video frame inspection)requiredrw   rP   evidencer   )r   rn   r-   r&   r   r   r   r   )rP   r   r   ).	PROMOTIONLAYOUTPOSTERPOSTER_RECEIPTWORKFLOW_COPYrb   rc   r^   rd   is_filera   r   r#   r_   r`   r   rj   r   r   r   floatr&   rL   GPU_BASERECEIPTr   OUTPUTprintrA   r"   r   r   uuiduuid4hexr   anyabsr   r   r   r   r   r   r   r   )r   	promotionlayoutrf   poster_receiptr   full_durationr   r   r   rI   r%   output_prober   r   rP   r   s                    r   mainr     sA
   FFNM6S]_lnuv 2 2||~~ 	20$00111	2
9...@@AAIZ(('(::;;FMM344Ej!!--J1G1Gt1S1Szz+r**..z::$FFzz/00E99:;;;Z 8 8' 8 J JKKNz**d22~7I7I(7S7SWb7b7bgugygy  {C  EG  hH  hH  hL  hL  MU  hV  hV  Z]  ^d  Ze  Ze  he  he  jx  j|  j|  }]  j^  j^  be  fs  bt  bt  jt  jtJKKK5!!!m, U U||~~ 	USTSSTTT	UJ}666HHIIM*%%--h'';66344==o..#f++==122c*ooEEo..#e**<<233s4yy@@GHHH%++h/
;<<M(Y.//Fzz(t##vzz)'<'<'L'LPVPZPZ[lPmPmuyPyPyJKKK~~ FMMOO j**G*<<==GGJ4''CGG4I,J,Je,S,SGGO,,F;;@W@W[^_c[d[d@d@dGG899S__LLGGO,,F;;$*$$#f++VVejkkklll1
Mt444!DJLL$4SbS$99F ~x  ~3v;;Ta,b,b+c  ~eqsvw{s|s|  ~  N  PT  ~  Vc  eh  io  ep  ep  ~  ry  {  ~  AI  KO  ~  QV  XZ  ~  \a  ce  ~  go  qu  ~  wG  IN  ~  P[  ]b  ~  ds  u{  ~  }I  KP  ~  Rg  il  ~  nw  y|  ~  ~H  JM  ~  ^c  x}  ~  ~  ~G(%;;WcRRRF>> IGHHH==Ly"--G\(+J788H7||q   AS(\(\T[(\(\(\%\%\  Aad  eX  eX  PW  eX  eX  eX  bX  bX  A  ]`  ai  ly  ay  ]z  ]z  ~A  ]AH1 (,4X6[kkS[u&FMHZHZ\~  AD  ES  AT  AT V^  `f hr  t| 	L +:6 DSTZ 	V	 '5c$ii	
 	s6{{
 -I#j// 	-c-.@.@ 	%c-&8&8 f((1122S[[$|0b [[
 
 l8<00::<<#  G& N555tz'aHHH4OZabbb	$*(f(SSbg
h
h
hiii11ar   __main__zIntro blocked: )file)Nr5   )1r   r   r   r    sysurllib.parserC   urllib.requestr  r.   r   r   pathlibr   __file__resolver   r   r   r  r  r  r  rb   rc   r^   rd   r   r   r	  r  r   r   r  rs   r   r&   r4   rL   rj   r   r   r  __name__exit	Exceptionexcr
  stderr r   r   <module>r$     sg     				     



           ' ' ' ' ' ' ' '      
$x..
 
 
"
"
*1
-,,		2	2AA??	8	8	1	1<<
<<
7
7))''	+	+
+
+00&&
  % % %	
 	
 	
# # # #  ** * *Z  $I  I  I X z   %%%CJ7777 s   C! !D&%DD