|
@@ -167,6 +167,49 @@ def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
|
|
|
#make title as image
|
|
|
txt2image_title(name, dir_title+name_hash+".png",lang)
|
|
|
|
|
|
+
|
|
|
+def file_prepare_long(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
|
|
|
+ make_dir(name_hash)
|
|
|
+ img_num = 1
|
|
|
+ for imgu in image_urls:
|
|
|
+ if get_url_type(imgu) =='video/mp4':
|
|
|
+ r=requests.get(imgu)
|
|
|
+ f=open(dir_photo+name_hash+"/"+str(img_num)+".mp4",'wb')
|
|
|
+ for chunk in r.iter_content(chunk_size=255):
|
|
|
+ if chunk:
|
|
|
+ f.write(chunk)
|
|
|
+ f.close()
|
|
|
+ else:
|
|
|
+ im = Image.open(requests.get(imgu, stream=True).raw)
|
|
|
+ im= im.convert("RGB")
|
|
|
+ im.save(dir_photo+name_hash+"/"+str(img_num)+".jpg")
|
|
|
+ img_num+=1
|
|
|
+
|
|
|
+ #make mp3
|
|
|
+ txt_idx = 0
|
|
|
+ for txt in text_content:
|
|
|
+ txt = txt.replace
|
|
|
+ if lang!='zh' or multiLang==1:
|
|
|
+ if lang!='zh':
|
|
|
+ tts = gTTS(txt)
|
|
|
+ tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
|
|
|
+ else:
|
|
|
+ tts = gTTS(txt,lang='zh-tw')
|
|
|
+ tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
|
|
|
+ #speed up
|
|
|
+ ff = ffmpy.FFmpeg(inputs={dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3": None}
|
|
|
+ , outputs={dir_sound+name_hash+"/"+str(txt_idx)+".mp3": ["-filter:a", "atempo=1.2"]})
|
|
|
+ ff.run()
|
|
|
+ os.remove(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
|
|
|
+ else:
|
|
|
+ print('use zhtts')
|
|
|
+ tts = zhtts.TTS()
|
|
|
+ tts.text2wav(txt,dir_sound+name_hash+"/"+str(txt_idx)+".mp3")
|
|
|
+ txt_idx+=1
|
|
|
+ print("mp3 file made")
|
|
|
+ #make title as image
|
|
|
+ txt2image_title(name, dir_title+name_hash+".png",lang)
|
|
|
+
|
|
|
def txt2image(content, save_target,lang='zh'):
|
|
|
unicode_text = trim_punctuation(content)
|
|
|
font = ''
|
|
@@ -326,8 +369,6 @@ def split_sentence(in_str, maxLen):
|
|
|
zh_eng_dict_list[-1]['time_ratio'] = 1-total_ratio
|
|
|
return zh_eng_dict_list
|
|
|
|
|
|
-
|
|
|
-
|
|
|
def parse_script(file_path,gt_list):
|
|
|
with open(file_path, 'r',encoding="utf-8") as f:
|
|
|
raw_lines = [line.strip() for line in f]
|
|
@@ -422,14 +463,6 @@ def splitter(s):
|
|
|
def split_by_pun(s):
|
|
|
res = list(splitter(s))
|
|
|
return res
|
|
|
-def split_by_word(s):
|
|
|
- slice_size = 3
|
|
|
- paragraph_len = len(s)
|
|
|
- slice_num = int(math.ceil(paragraph_len/slice_size))
|
|
|
- slice_list = []
|
|
|
- for n in range(slice_num):
|
|
|
- slice_list.append(s[n*slice_size:n*slice_size+slice_size])
|
|
|
- return slice_list
|
|
|
|
|
|
def generate_subtitle_image_from_dict(name_hash, sub_dict):
|
|
|
for script in sub_dict:
|
|
@@ -468,7 +501,7 @@ def video_writer_init(path):
|
|
|
|
|
|
|
|
|
def video_gen(name_hash,name,text_content, image_urls,multiLang,avatar):
|
|
|
- file_prepare(name, name_hash, text_content,image_urls,multiLang)
|
|
|
+ file_prepare_long(name, name_hash, text_content,image_urls,multiLang)
|
|
|
|
|
|
for fname in range(len(text_content)):
|
|
|
call_anchor(name_hash+"/"+str(fname),avatar)
|