|
@@ -125,7 +125,19 @@ def make_dir(name_hash):
|
|
|
except FileExistsError:
|
|
|
print("~~~~~~Warning~~~~~~~~~Directory " , dir_subtitle+name_hash , " already exists")
|
|
|
|
|
|
-def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
|
|
|
+def Check_text_content(text_content):
|
|
|
+ mulitLang = 0
|
|
|
+ status = False
|
|
|
+ for txt in text_content:
|
|
|
+ if re.search('[a-zA-Z]', txt) !=None:
|
|
|
+ mulitLang = 1
|
|
|
+ if re.search(',', txt) !=None:
|
|
|
+ print('包含非法符號')
|
|
|
+ status = {'msg':{'eng':'symbol "," is not allowede','zh':'輸入不能含有","符號'}}
|
|
|
+ return mulitLang, status
|
|
|
+
|
|
|
+def file_prepare(name, name_hash,text_content,image_urls):
|
|
|
+ mulitLang, status = Check_text_content(text_content)
|
|
|
make_dir(name_hash)
|
|
|
img_num = 1
|
|
|
for imgu in image_urls:
|
|
@@ -152,13 +164,9 @@ def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
|
|
|
#make mp3
|
|
|
txt_idx = 0
|
|
|
for txt in text_content:
|
|
|
- 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")
|
|
|
+ if multiLang==1:
|
|
|
+ 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"]})
|
|
@@ -171,7 +179,7 @@ def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
|
|
|
txt_idx+=1
|
|
|
print("mp3 file made")
|
|
|
#make title as image
|
|
|
- txt2image_title(name, dir_title+name_hash+".png",lang)
|
|
|
+ txt2image_title(name, dir_title+name_hash+".png")
|
|
|
|
|
|
|
|
|
def file_prepare_long(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
|
|
@@ -220,6 +228,7 @@ def file_prepare_long(name, name_hash,text_content,image_urls,multiLang,lang='zh
|
|
|
txt2image_title(name, dir_title+name_hash+".png",lang)
|
|
|
|
|
|
def txt2image(content, save_target,lang='zh'):
|
|
|
+ mulitLang, status = Check_text_content(text_content)
|
|
|
unicode_text = trim_punctuation(content)
|
|
|
font = ''
|
|
|
if lang=='zh':
|