Browse Source

add multi lang

ming 3 years ago
parent
commit
c134b06a0a

+ 6 - 6
OpenshotService/openshot_video_generator.py

@@ -108,7 +108,7 @@ 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,lang='zh'):
+def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
     make_dir(name_hash)
     img_num = 1
     for imgu in image_urls:
@@ -136,7 +136,7 @@ def file_prepare(name, name_hash,text_content,image_urls,lang='zh'):
     language = 'zh-tw'
     txt_idx = 0
     for txt in text_content:
-        if lang!='zh':
+        if lang!='zh' or multiLang==1:
             tts = gTTS(txt)
             tts.save(dir_sound+name_hash+"/"+str(txt_idx)+".mp3")
         else:
@@ -251,10 +251,10 @@ def generate_subtitle_image_ENG(name_hash,text_content):
         img_list[idx] = sv_path
     return img_list
 
-def anchor_video_v2(name_hash,name,text_content, image_urls,avatar):
+def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
     print(os.getcwd())
     print('sub image made')
-    file_prepare(name, name_hash, text_content,image_urls)
+    file_prepare(name, name_hash, text_content,multiLang,image_urls)
     sub_list=generate_subtitle_image(name_hash,text_content)
     
     for fname in range(len(text_content)):
@@ -536,8 +536,8 @@ def anchor_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar):
 
 
 class video_service(rpyc.Service):
-    def exposed_call_video(self,name_hash,name,text_content, image_urls,avatar):
-        anchor_video_v2(name_hash,name,text_content, image_urls,avatar)
+    def exposed_call_video(self,name_hash,name,text_content, image_urls,multiLang,avatar):
+        anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar)
     def exposed_call_video_eng(self,name_hash,name,text_content, image_urls,sub_titles,avatar):
         anchor_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar)
 

+ 3 - 3
api/main.py

@@ -231,7 +231,7 @@ async def make_anchor_video(req:models.request,token: str = Depends(oauth2_schem
             return {'msg':"無法辨別圖片網址"+imgu}
     user_id = get_user_id(token)
     save_history(req,name_hash,user_id)
-    x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),user_id))
+    x = threading.Thread(target=gen_video_queue, args=(name_hash,req.name, req.text_content, req.image_urls,int(req.avatar),req.multiLang,user_id))
     x.start()
     return {"msg":"製作影片需要時間,請您耐心等候,成果會傳送至LINE群組中"} 
 
@@ -407,7 +407,7 @@ def gen_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar):
     shutil.copy(tmp_video_dir+name_hash+'.mp4',video_dest+name_hash+'.mp4')
     os.remove(tmp_video_dir+name_hash+'.mp4')
 
-def gen_video_queue(name_hash,name,text_content, image_urls,avatar,user_id):
+def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,user_id):
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
     time_stamp = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
     txt_content_seperate_by_dot = ''
@@ -434,7 +434,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,user_id):
             c = rpyc.connect("localhost", 8858)
             c._config['sync_request_timeout'] = None
             remote_svc = c.root
-            my_answer = remote_svc.call_video(top1['name_hash'],top1['name'],top1['text_content'].split(','), top1['image_urls'].split(','),top1['avatar']) # method call
+            my_answer = remote_svc.call_video(top1['name_hash'],top1['name'],top1['text_content'].split(','), top1['image_urls'].split(','),top1['multiLang'],top1['avatar']) # method call
             shutil.copy(tmp_video_dir+top1['name_hash']+'.mp4',video_dest+top1['name_hash']+'.mp4')
             os.remove(tmp_video_dir+top1['name_hash']+'.mp4')
             vid_duration = VideoFileClip(video_dest+top1['name_hash']+'.mp4').duration

+ 1 - 0
api/models.py

@@ -15,6 +15,7 @@ class request(BaseModel):
     image_urls: List[str]
     avatar: str
     client_id :str
+    multiLang :int
 
 class request_eng(BaseModel):
     name: str

+ 3 - 1
api/static/script_util.js

@@ -100,7 +100,9 @@ $(".next").click(function () {
       imgARR.push($(`.imgsrc${i}`).val())
     }
   }
-  dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar, "client_id": client_id }
+  multiLang = 0
+  if ($('#multiLang').prop("checked")) {multiLang = 1;}
+  dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang, "client_id": client_id }
   objstr = JSON.stringify(dataOBJ);
   console.log(dataOBJ)
   jwt_token =  get_jwt_token()

+ 2 - 0
api/templates/make_video.html

@@ -88,6 +88,8 @@
         </fieldset>
         <fieldset>
           <h3 class="fs-subtitle">台詞</h3>
+          
+<input type="checkbox" id="multiLang" ><label for="myCheck">Checkbox:</label> 
           <div class="subtitle-inputs">
           
           </div>