+
    DIj
.                         R t ^ RI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	t	R t
R tR tR tR tR tR	 t]R
8X  d
   ]! 4        R# R# )uM   
截取中文音频并拼接双语音频
用法: python joinbiliad.py <adid>
N)datetimec           
     n   RRRRRRRRR	V  2.	p\         P                  ! VR
R
R7      pVP                  '       d   ^ #  \        \	        VP
                  P                  4       4      R,          4      #   \         d:   p\        RT4       \        RT 4       \        RTP
                  4        Rp?^ # Rp?ii ; i)u&   
获取音频文件时长（毫秒）
ffprobez-vquietz-show_entrieszformat=durationz-ofz"default=noprint_wrappers=1:nokey=1-izfile:T)capture_outputtext  xxxzffprobe file=z stdout:N)	
subprocessrun
returncodeintfloatstdoutstrip	Exceptionprint)	file_pathcmdresultexs   &   )c:\dev\xtrs\vdcb\srtsegjoin\joinbiliad.pyget_file_durationr      s    
 T7O5FOsuy  }B  CL  BM  {N  OC^^C4@F 5,,./$677 eBoi(j'	s   2A0 0B4;.B//B4c           	     V   ^ RI pVP                  4       P                  P                  pVP                  4       P                  pRpRp \        ^4       \        P                  ! VRR7      p VP                  R4       VP                  R4       VP                  R4       TP                  4       pTP                  RT 34       \        ^4       . pTP                  4        F3  p	T	w  rrp\        T4      p\        T4      pTP                  YTY34       K5  	  \        ^\        T4      4       TT'       d   TP                  4        T'       d   TP                  4        # #   \         d   pTP                  4        h Rp?ii ; i  \         df   p^ RIp\        RT R	T R
T 24       TP#                  4        . u Rp?T'       d   TP                  4        T'       d   TP                  4        # # Rp?ii ; i  T'       d   TP                  4        T'       d   TP                  4        i i ; i)u    
从数据库获取字幕信息
N      N@timeoutzPRAGMA journal_mode=WAL;zPRAGMA synchronous=NORMALzPRAGMA cache_size=-64000zt
            SELECT idx, start, end, cn, en FROM srts 
            WHERE adid = ? 
            ORDER BY idx
           错误 [函数: 
   , 行号:    ]: 操作失败: )inspectcurrentframef_codeco_namef_linenor   sqlite3connectexecuter   closecursorfetchallr   appendlen	traceback	print_exc)adiddb_pathr!   	func_nameline_noconnr*   e	subtitlesrowidxstartendcnenstart_msend_msr.   s   &&                r   get_subtitlesr?   %   s    $$&--55I""$--GDF#aw5	LL34LL45LL34   W		
 	a	??$C&)#C5zHXFcVR<=	 %
 	aI LLNJJL 5  	JJL	$   :gY>OPQsST	LLNJJL  LLNJJL s[   #F ,3E BF E?)E::E??F G2)G-6G27G5 -G22G5 5 H(H(c                      R V  2p\         P                  ! V4      pVP                  4       pV#   \         d.   p^ RIp\        RT 24       TP                  4         Rp?. # Rp?ii ; i)z%http://ll:899/api/reqsrts4makebilivd/Nu   xxx 操作失败: )requestsgetjsonr   r.   r   r/   )r0   r1   urlrespqrsrtsr5   r.   s   &&     r   r?   r?   R   sh    3D6:\\#yy{ "1#&'I	s   ,/ A'"A""A'c           	        ^ RI pVP                  4       P                  P                  pVP                  4       P                  pRp \
        P                  ! VRR7      pVP                  4       pVP                  RV 34       VP                  4       pV'       d#   V^ ,          V'       d   VP                  4        # # RV  2V'       d   VP                  4        # #   \         dQ   p^ RIp	\        RT RT RT 24       T	P                  4        RT  2u Rp?T'       d   TP                  4        # # Rp?ii ; i  T'       d   TP                  4        i i ; i)	u   
从数据库获取adname
Nr   r   z7SELECT DISTINCT adname FROM srts WHERE adid = ? LIMIT 1adid_r   r   r    )r!   r"   r#   r$   r%   r&   r'   r*   r(   fetchoner)   r   r.   r   r/   )
r0   r1   r!   r2   r3   r4   r*   r   r5   r.   s
   &&        r   
get_adnamerJ   ]   s$    $$&--55I""$--GDw5PSWRYZ"!9 JJL  tf~ JJL    :gY>OPQsSTtf~JJL  JJL s7   AC ;C D4$,D/D4D7 /D44D7 7Ec                t    V R,          pRRRRRRR\        V4      R	R
V.p\        P                  ! VRR7       R# )u#   
生成指定长度的静音音频
r	   ffmpeg-y-flavfir   z0anullsrc=channel_layout=stereo:sample_rate=44100-t-acodec
libmp3lameTr   N)strr   r   )duration_msoutput_pathduration_secr   s   &&  r   generate_silencerX   z   sG     %L$g@c,<C NN3t,    c                   Rp\        RV 24       \        P                  P                  RV R24      p\        RV 24       \        P                  P	                  V4      '       g   \        RV 24       R# \        V4      p\        RVR	,           R
24       V R2p\        P                  P                  RRV4      p\        P                  P	                  V4      '       g   \        RV 24       R# \        P                  P	                  V4      '       d    \        P                  ! V4        \        P                  ! VRR7       \        R4       \        Y4      p\        R\        T4       R24       T'       g   \        R4       R# \        R4       . p	\        T4       EF?  w  p
w  rrpT
^ 8  d   Y^,
          ,          ^,          M^ pT
^ 8  d
   TT,
          M^ pT
\        T4      ^,
          8  d!   Y^,           ,          ^,          pTT,
          pMTpYM8  d
   TT,
          M^ pT
^ 8X  d   ^ pMTT,           ^,          pT
\        T4      ^,
          8X  d   T^,
          pMTT,           ^,          pT
^ 8X  d   ^ pMRTT,
          ,
          pT^ 8:  d   ^ pT
\        T4      ^,
          8X  d   ^ pMRTT,
          ,
          pT^ 8:  d   ^ pT	P                  YTTTTTY3	4       EKB  	  \        R4       \        T	4       EFG  w  p
w	  rppppprTR	,          pTT,
          R	,          p\        P                  P                  TRTR R24      pRRR\        T4      R\        T4      R TR!R"R#R$R%R&T.p\        P                   ! TRR'7       \        T4      pRTR R(T R(T R(T R2	p\        P                  P                  TT4      p\        P                  P	                  T4      '       d   \        P"                  ! T4       \        P$                  ! TT4       T
^d,          ^ 8X  g   EK&  \        R)T
^,            R*\        T	4       24       EKJ  	  \        R+\        T	4       R,24       \        R-T 24       \        R.4       \&        P(                  ! 4       ;_uu_ 4       p\        P                  P                  TR/4      p \+        T R0R1R27      ;_uu_ 4       p!\        T	4       EF  w  p
w	  rpppppr\        P                  P                  TRTR R(T R(T R324      p"\,        P,                  ! T"4      p#T#'       d<   \        P                  P/                  T#^ ,          4      p$T!P1                  R4T$ R524       T'       dl   T^ 8  de   \        P                  P                  TR6T R24      p%\3        TT%4       \        P                  P/                  T%4      p&T!P1                  R4T& R524       \        P                  P                  TR7TR8 R24      p'\,        P,                  ! T'4      p(T('       d   T(^ ,          p)\        P                  P                  TR9TR8 R24      p*\        P                   ! RRR T)R:R;R%R&R#R$T*.RR'7       \        P                  P/                  T*4      p+T!P1                  R4T+ R524       T
^d,          ^ 8X  d   \        R<T(^ ,           24       T
\        T	4      ^,
          8  g   EK  Y^,           ,          ^,          p,T,'       g   EK,  T,^ 8  g   EK6  \        P                  P                  TR=T
^,            R24      p%\3        T,T%4       \        P                  P/                  T%4      p&T!P1                  R4T& R524       EK  	  RRR4       T R>2p-RRR?R@RARBR T R!R"R#R$R%R&T-.p\        RC4       \        P                   ! TRR'7      p.T.P4                  ^ 8X  d   \        RDT- 24        RRR4       R#  T.P6                  P9                  R1RERF7      p/\        RHT/ 24        RRR4       R#   \         d   p\        RT 24        Rp?ELRp?ii ; i  \         d   p\        RT 24        Rp?R# Rp?ii ; i  + '       g   i     L; i    T.P6                  P9                  RGRERF7      p/ L   \        T.P6                  4      p/  L; i; i  + '       g   i     R# ; i)Iu)   
截取中文音频并拼接双语音频
z\\ll\D\xtrssvjj\db\dpd.dbzadname: z\\ll\D\xtrssvjjz.mp3u   音频文件: u    错误：音频文件不存在: Fu   音频总长度: r	   u    秒	_cn_audiottsu#   错误：英文TTS目录不存在: u   警告：删除目录失败: NT)exist_oku   错误：创建目录失败: u$   从数据库中查询字幕句数...u   找到 u
    句字幕u   错误：未找到字幕信息u   调整字幕句时间...i  u*   
=== 步骤1: 截取中文音频片段 ===seg03drL   rM   z-ssrP   r   rQ   rR   z-ar44100z-ac2rS   -u   截取音频 /u   完成！截取了 u    个音频片段u   输出目录: u$   
=== 步骤2: 拼接双语音频 ===zfilelist.txtwzutf-8)encodingz-*.mp3zfile 'z'
silence_end_z*-04dslowed_tts_z	-filter:az
atempo=0.7u   添加 TTS 文件 (70%速度): silence_start_z_bilingual.mp3rN   concatz-safe0u   开始拼接双语音频...u   拼接完成！输出文件: replace)errorsgbku   拼接失败！错误信息: )r   ospathjoinexistsr   shutilrmtreer   makedirsr?   r-   	enumerater,   rT   r   r   removerenametempfileTemporaryDirectoryopenglobabspathwriterX   r   stderrdecode)0r0   adnamer1   
audio_fileaudio_durationcn_audio_dir
en_tts_dirr5   r6   enhanced_subtitlesir8   r9   r:   r;   r<   prevendstartgap	nextstartendgapstartposendposaddstartaddend	start_secrW   rV   r   actual_durationnew_filenamenew_pathtemp_dirfilelist_pathfcn_audio_filecn_filescn_file_abssilence_filesilence_file_absen_tts_patternen_tts_filestts_fileslowed_tts_fileen_tts_file_absnext_addstartoutput_filer   	error_msgs0   &&                                              r   extract_and_combiner      s    +G	HVH
0VHD/BJ	N:,
'(77>>*%%0=>&z2N	nT12$
78XY'L0%@J77>>*%%3J<@A	ww~~l##	7MM,'
L40 

01d,I	GC	N#:
././	
$%(1)(<$$C'(1u)aC.#!&'!e57?s9~a!A#q)I_F&I(6(<Y_!F6H%A-HIq  #a'FIo!+F6Heh./H1}Iq  FFSL)F{!!3sHfhPVXZ"_`G )=J 

78LUVhLiHHCXvxtO	)T1ggll<3s3it1DE d3y>#l#*|73	
 	s40+K8SIQxj&?:K4P77<<l;77>>(##IIh
		+x(s7a<M!A#a,>(?'@AB; Mj> 
$6 788H
IJ	N<.
)*	
12		$	$	&	&(X~>-w771T]^pTqPPCXvx "\SS	8*TUV\U]]c;d e99]3"$''//(1+">KGGf[M56fqj#%77<<LT:R#SL$V\:')ww|'D$GGf%5$6c:; "$jBs3it:L!M#yy8+AH&(ggll8{3s)SW=X&YONN $h#\sE7'	$
 '+, ')ggooo&FOGGf_$5S9:uax ?Q?PQRs-.22$6s$;A$>M$}):')ww||HqQRseSW>X'Y(E+-77??<+H(&)9(:# >?M Ur 8R  /d(S-|73	
 	+,D9!1+?@{ 
'	&~3"MM000K	 1)=>O 
'	&s  	71!566	7  -aS12p 87|33 & 4 4U9 4 MI3 #FMM 2IK 
'	&	&s   `" 0a	 7cB&a0	5B-a0	#B<a0	%a0	a0	A0a0	 A!c,b	c"a-aa	a-a((a-0b ;ccb%#c%b?	<c=c?ccc	c                    \        \        P                  4      ^8w  d-   \        R4       \        R4       \        P                  ! ^4        \        \        P                  ^,          4      p \        R4       \        RX  24       \        V 4      pV'       d   \        R4       R# \        R4       \        P                  ! ^4       R#   \         d%    \        R4       \        P                  ! ^4        Li ; i)	u   
主函数
u#   用法: python joinbiliad.py <adid>u!   示例: python joinbiliad.py 8496u   错误：adid必须是数字u    === 双语音频制作工具 ===zadid: u   
制作完成！u   
制作失败！N)r-   sysargvr   exitr   
ValueErrorr   )r0   successs     r   mainr   G  s     388}3412388A;
 
,.	F4&/!$'G!"!"  ,-s    C ,C76C7__main__)__doc__ro   r   r&   r   rs   ry   r|   r   rA   r   r?   rJ   rX   r   r   __name__ rY   r   <module>r      sa   
 
 
       $,Z
:- zz6 zF rY   