ming 3 роки тому
батько
коміт
81161db087
1 змінених файлів з 25 додано та 1 видалено
  1. 25 1
      main.py

+ 25 - 1
main.py

@@ -410,7 +410,22 @@ def call_achor_video(name):
     print('called............................................')
 
 
+def trim_punctuation(s):
+    pat_block = u'[^\u4e00-\u9fff0-9a-zA-Z]+';
+    pattern = u'([0-9]+{0}[0-9]+)|{0}'.format(pat_block)
+    res = re.sub(pattern, lambda x: x.group(1) if x.group(1) else u"" ,s)
+    return res
+
+def splitter(s):
+    for sent in re.findall(u'[^!?,。\.\!\?]+[!?。\.\!\?]?', s, flags=re.U):
+        yield sent
+
+def split_by_pun(s):
+    res = splitter(s)
+    return res
+
 def generate_subtitle_image(name_hash,text_content):
+    '''
     sub_len = 10
     img_list = [None]*len(text_content)
     for idx in range(len(text_content)):
@@ -421,6 +436,16 @@ def generate_subtitle_image(name_hash,text_content):
             txt2image(sub, sv_path)
             img_list[idx] += [{"count":len(sub),"path":sv_path}]
             print(sub+':'+sv_path)
+    '''
+    img_list = [None]*len(text_content)
+    for idx in range(len(text_content)):
+        img_list[idx]=[]
+        senList = split_by_pun(text_content[idx])
+        for inner_idx in range(len(senList)):
+            sv_path = dir_subtitle + name_hash +'/'+str(idx)+ str(step) +'.png'
+            sub = senList[inner_idx]
+            txt2image(sub,sv_path)
+            img_list[idx]+=[{"count":len(sub),"path":sv_path}]
     return img_list
 
 
@@ -598,7 +623,6 @@ def anchor_video_v2(name,text_content, image_urls):
     sub_img_list = [None] * len(text_content)
     
     idx = 0
-    #mp4 also
     for p in listdir(dir_photo+name_hash):
         
         anchor_list[idx] = openshot.FFmpegReader(dir_anchor+name_hash+"/"+str(idx)+".mp4")