@
haha512 谢谢,我只需要其中一部分自己包一下就能用了,多谢。
sp.pyfrom googletrans import Translator
text = f"{text.capitalize()}. " # .decode('utf-8').encode('gbk')
try:
#################### modify src='ja', dest="zh-cn" to define the source and target language ##########
## You can find all the possible language here:
#
https://py-googletrans.readthedocs.io/en/latest/#googletrans-languages # google 翻译
transd = translator.translate(text, src=video_config['source_language'],
dest=video_config['target_language']) # en zh-cn
result = transd.text # .decode('utf-8').encode('gbk')
except Exception as e:
print("Translate Error:", str(e))
continue
translator = Translator(service_urls=['
translate.googleapis.com'])
r = sr.Recognizer()
# subtitles
if video_config['subtitle_out']=='双字幕':
combo_txt = text + '\n' + result + '\n\n'
else:
combo_txt = result + '\n\n'
if buffered:
# start_time += 2000
end_time -= 2000
start = timedelta(milliseconds=start_time)
end = timedelta(milliseconds=end_time)
index = len(subs) + 1
sub = srt.Subtitle(index=index, start=start, end=end, content=combo_txt)
subs.append(sub)
# whole_text += text
# whole_trans += result
final_srt = srt.compose(subs)
# todo 字幕合并
with open(sub_name, 'w', encoding="utf-8") as f:
f.write(final_srt)
qu.put(f" [get_large_audio_transcription] 生成字幕文件:final_str")
else:
qu.put(f"字幕文件已存在,直接使用 {sub_name=}")
updatebtn(mp4name, "开始合成字幕")