
    >j                         d dl Z d dlZd dlZd dlmZ d dlZ ed          Zd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edk    r e             dS dS )    N)PathzG/data/video-pipeline/Youtube-Video-Maker/Project/26052026-001-Ngo-Quyenz%http://192.168.1.104:8005/compose-ttsaudiosceneszmaster_narration.wavzmaster_narration_timeline.jsonz$logs/step8_compose_tts_manifest.jsong      ?c                 V    t          j        d          | z   }t          |d           d S )Nz%Y-%m-%d %H:%M:%S T)flush)timestrftimeprint)msglines     AProject/26052026-001-Ngo-Quyen/scripts_run_step_08_compose_tts.pylogr      s0    =-..4D	$d    c                     t          j        t          |           d          5 }|                                t	          |                                          z  cd d d            S # 1 swxY w Y   d S )Nrb)waveopenstr
getnframesfloatgetframerate)pathwavs     r   wav_durationr      s    	3t99d	#	# <s~~%(8(8(:(:";";;< < < < < < < < < < < < < < < < < <s   6A&&A*-A*c                  
   t          j        t          dz                      d                    d         } t                              dd           t          j                            dd           d}g }g }g }t          | d	          D ]\  }}|d
         }t          | dz  }|
                                s#|                    t          |                     R|                    d          p|                    dd          }	|	dk    rt          nd}
|	dk    rt          nd}||
z  }t!          |          }t#          |d          }t#          ||z   d          }|||	t          |                    t                              t          |          ||t#          |d          |
||                    dd          d}|                    |           |                    |||t          |          |                    dd          ddd           ||z   }|r.t'          dt          j        |d d         d          z             t          j        dz   t          t                    t          t,                    |d}t.          j                            t4          t          j        |d                              d          ddid          }t9          dt4           d t;          |           d!t,                      t.          j                            |d"#          5 }t          j        |                                                     d                    }d d d            n# 1 swxY w Y   |                    d$          }t          j        d%t          t,                              t                              t          t,                    t4          t          t          d&t;          |          ||d'	}tB          "                    t          j        |dd()          d           t          j        d%d*t4          |d+         |d,         |d-         t;          |          d.|t          tB                    t          t,                    d/}t          "                    t          j        |dd()          d           t9          d0t          j        d*t;          |          t#          |pd1d2z  d(          d3d          z              d S )4Nzscript/scenes.jsonzutf-8)encodingr   T)parentsexist_okg           )startscene_idz.wav
scene_typetype heading   	narration)orderr!   r"   
audio_pathabsolute_audio_pathr    endduration	pre_pause
post_pauser'   ok)segment_indexr    r+   r)   source_texttranslated_textstatuszMissing scene audio files: 
   F)ensure_ascii_step8_master_narration)job_idwork_diroutput_audio_pathtts_segmentszContent-Typezapplication/jsonPOST)dataheadersmethodzPOST z
 segments=z output=i  )timeoutr,      )pre_heading_secondspost_heading_seconds)	
project_idstepmaster_audiomaster_audio_absoluteendpointpause_rulestotal_scenestotal_durationtimeline   )r5   indent	completedr7   r8   r9   )r7   r8   r9   segments_count)rC   rD   r3   rG   requestworker_responsetimeline_pathmaster_audio_pathzDONE r   <   )r3   segmentsduration_min)#jsonloadsPROJECT	read_text	AUDIO_DIRmkdirMANIFESTparent	enumerate
SCENES_DIRexistsappendr   getPRE_HEADING_PAUSEPOST_HEADING_PAUSEr   roundrelative_to
SystemExitdumpsnameMASTER_AUDIOurllibrP   RequestENDPOINTencoder   lenurlopenreaddecodeTIMELINE
write_text)r   trK   rU   missingr(   scener!   r)   r"   r-   r.   r,   r    r+   timeline_itempayloadreqresprQ   rJ   timeline_docmanifests                          r   mainr      sk   Z#77BBGBTTUUV^_FOOD4O000O$666AHHG!&222 ' 'u$X"3"3"33
  "" 	NN3z??+++YY|,,E		&"0E0E
)3y)@)@%%c	+5+B+B''
	Y
++aAL!$$  $j44W==>>#&z??h**"$;33
 
 	&&&"j// 99["55!
 
 	 	 	 * g6GCRCL_d9e9e9eefff ,!::LL .. 	 G .
 
 Ze444;;GDD!34	 !  C IIICMMII<IIJJJ			T		2	2 Bd*TYY[[%7%7%@%@AAB B B B B B B B B B B B B B B %((44NlL44W==>>!$\!2!2#4$6
 
 H( L 
<eANNNY`aaa lh'
+!()<!=!(mm	
 
 +X .. H 
8%JJJU\]]]$*X`egugzyz  A  gA  CD  aE  aE  F  F  UZ  [  [  [  	[  \  \  \  \  \s   $:M**M.1M.__main__)rW   r   urllib.requestrl   pathlibr   r   rY   rn   r[   r`   rk   rt   r]   rd   re   r   r   r   __name__ r   r   <module>r      s                
$X
Y
Y2g	!
1177;;    
< < <
h\ h\ h\V zDFFFFF r   