openshot_video_generator.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. from os import listdir
  2. from os.path import isfile, isdir, join
  3. import openshot
  4. import threading
  5. import zhtts
  6. import os
  7. import urllib
  8. from typing import List
  9. import requests
  10. from pydantic import BaseModel
  11. from bs4 import BeautifulSoup
  12. from PIL import Image,ImageDraw,ImageFont
  13. import pyttsx3
  14. import rpyc
  15. import random
  16. import re
  17. import time
  18. import math
  19. import dataset
  20. from datetime import datetime
  21. from gtts import gTTS
  22. import ffmpy
  23. from difflib import SequenceMatcher
  24. import difflib
  25. from autosub import DEFAULT_CONCURRENCY
  26. from autosub import DEFAULT_SUBTITLE_FORMAT
  27. from pytranscriber.control.ctr_main import Ctr_Main
  28. from pytranscriber.control.ctr_autosub import Ctr_Autosub
  29. import multiprocessing
  30. from itertools import groupby
  31. from operator import itemgetter
  32. from util.parser import parser
  33. dir_sound = 'mp3_track/'
  34. dir_photo = 'photo/'
  35. dir_text = 'text_file/'
  36. dir_video = 'video_material/'
  37. dir_title = 'title/'
  38. dir_subtitle = 'subtitle/'
  39. dir_anchor = 'anchor_raw/'
  40. tmp_video_dir = 'tmp_video/'
  41. video_sub_folder = 'ai_anchor_video/'
  42. dir_list = [dir_sound,dir_photo,dir_text,dir_video,dir_title,dir_subtitle,dir_anchor,tmp_video_dir]
  43. def notify_group(msg):
  44. glist=['7vilzohcyQMPLfAMRloUawiTV4vtusZhxv8Czo7AJX8','WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD','1dbtJHbWVbrooXmQqc4r8OyRWDryjD4TMJ6DiDsdgsX','HOB1kVNgIb81tTB4Ort1BfhVp9GFo6NlToMQg88vEhh']
  45. for gid in glist:
  46. headers = {
  47. "Authorization": "Bearer " + gid,
  48. "Content-Type": "application/x-www-form-urlencoded"
  49. }
  50. params = {"message": msg}
  51. r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
  52. def cKey(r,g,b,fuzz):
  53. col=openshot.Color()
  54. col.red=openshot.Keyframe(r)
  55. col.green=openshot.Keyframe(g)
  56. col.blue=openshot.Keyframe(b)
  57. return openshot.ChromaKey(col, openshot.Keyframe(fuzz))
  58. def video_photo_clip(vid=None,layer=None, position=None, end=None
  59. ,scale_x=1,scale_y=1,location_x=0,location_y=0,ck=None,audio=True):
  60. clip = openshot.Clip(vid)
  61. clip.Layer(layer)
  62. clip.Position(position)
  63. clip.End(end)
  64. clip.scale_x=openshot.Keyframe(scale_x)
  65. clip.scale_y=openshot.Keyframe(scale_y)
  66. clip.location_x=openshot.Keyframe(location_x)
  67. clip.location_y=openshot.Keyframe(location_y)
  68. if ck!=None:
  69. clip.AddEffect(ck)
  70. if audio==True:
  71. clip.has_audio=openshot.Keyframe(1)
  72. else:
  73. clip.has_audio=openshot.Keyframe(0)
  74. return clip
  75. def listener_progress(string, percent):
  76. True
  77. def myunichchar(unicode_char):
  78. mb_string = unicode_char.encode('big5')
  79. try:
  80. unicode_char = unichr(ord(mb_string[0]) << 8 | ord(mb_string[1]))
  81. except NameError:
  82. unicode_char = chr(mb_string[0] << 8 | mb_string[1])
  83. return unicode_char
  84. def get_url_type(url):
  85. req = urllib.request.Request(url, method='HEAD', headers={'User-Agent': 'Mozilla/5.0'})
  86. r = urllib.request.urlopen(req)
  87. contentType = r.getheader('Content-Type')
  88. return contentType
  89. def make_dir(name_hash):
  90. for direct in dir_list:
  91. if not os.path.isdir(direct):
  92. os.mkdir(direct)
  93. try:
  94. os.mkdir(dir_photo+name_hash)
  95. except FileExistsError:
  96. print("~~~~~~Warning~~~~~~~~~Directory " , dir_photo+name_hash , " already exists")
  97. try:
  98. os.mkdir(dir_text+name_hash)
  99. except FileExistsError:
  100. print("~~~~~~Warning~~~~~~~~~Directory " , dir_text+name_hash , " already exists")
  101. try:
  102. os.mkdir(dir_sound+name_hash)
  103. except FileExistsError:
  104. print("~~~~~~Warning~~~~~~~~~Directory " , dir_sound+name_hash , " already exists")
  105. try:
  106. os.mkdir(dir_anchor+name_hash)
  107. except FileExistsError:
  108. print("~~~~~~Warning~~~~~~~~~Directory " , dir_anchor+name_hash , " already exists")
  109. try:
  110. os.mkdir(dir_subtitle+name_hash)
  111. except FileExistsError:
  112. print("~~~~~~Warning~~~~~~~~~Directory " , dir_subtitle+name_hash , " already exists")
  113. def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
  114. make_dir(name_hash)
  115. img_num = 1
  116. for imgu in image_urls:
  117. if get_url_type(imgu) =='video/mp4':
  118. r=requests.get(imgu)
  119. f=open(dir_photo+name_hash+"/"+str(img_num)+".mp4",'wb')
  120. for chunk in r.iter_content(chunk_size=255):
  121. if chunk:
  122. f.write(chunk)
  123. f.close()
  124. else:
  125. im = Image.open(requests.get(imgu, stream=True).raw)
  126. im= im.convert("RGB")
  127. im.save(dir_photo+name_hash+"/"+str(img_num)+".jpg")
  128. img_num+=1
  129. #save text
  130. txt_idx=0
  131. for txt in text_content:
  132. text_file = open(dir_text+name_hash+"/"+str(txt_idx)+".txt", "w")
  133. text_file.write(txt)
  134. text_file.close()
  135. txt_idx+=1
  136. print("text file made")
  137. #make mp3
  138. txt_idx = 0
  139. for txt in text_content:
  140. if lang!='zh' or multiLang==1:
  141. if lang!='zh':
  142. tts = gTTS(txt)
  143. tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
  144. else:
  145. tts = gTTS(txt,lang='zh-tw')
  146. tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
  147. #speed up
  148. ff = ffmpy.FFmpeg(inputs={dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3": None}
  149. , outputs={dir_sound+name_hash+"/"+str(txt_idx)+".mp3": ["-filter:a", "atempo=1.2"]})
  150. ff.run()
  151. os.remove(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
  152. else:
  153. print('use zhtts')
  154. tts = zhtts.TTS()
  155. tts.text2wav(txt,dir_sound+name_hash+"/"+str(txt_idx)+".mp3")
  156. txt_idx+=1
  157. print("mp3 file made")
  158. #make title as image
  159. txt2image_title(name, dir_title+name_hash+".png",lang)
  160. def file_prepare_long(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
  161. make_dir(name_hash)
  162. img_num = 1
  163. for imgu in image_urls:
  164. if get_url_type(imgu) =='video/mp4':
  165. r=requests.get(imgu)
  166. f=open(dir_photo+name_hash+"/"+str(img_num)+".mp4",'wb')
  167. for chunk in r.iter_content(chunk_size=255):
  168. if chunk:
  169. f.write(chunk)
  170. f.close()
  171. else:
  172. im = Image.open(requests.get(imgu, stream=True).raw)
  173. im= im.convert("RGB")
  174. im.save(dir_photo+name_hash+"/"+str(img_num)+".jpg")
  175. img_num+=1
  176. #make mp3
  177. text_parser = parser()
  178. txt_idx = 0
  179. for txt in text_content:
  180. rep_list = text_parser.replace_list(txt)
  181. for reptxt in rep_list:
  182. txt = txt.replace(reptxt,'')
  183. if lang!='zh' or multiLang==1:
  184. if lang!='zh':
  185. tts = gTTS(txt)
  186. tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
  187. else:
  188. tts = gTTS(txt,lang='zh-tw')
  189. tts.save(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
  190. #speed up
  191. ff = ffmpy.FFmpeg(inputs={dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3": None}
  192. , outputs={dir_sound+name_hash+"/"+str(txt_idx)+".mp3": ["-filter:a", "atempo=1.2"]})
  193. ff.run()
  194. os.remove(dir_sound+name_hash+"/"+str(txt_idx)+"raw.mp3")
  195. else:
  196. print('use zhtts')
  197. tts = zhtts.TTS()
  198. tts.text2wav(txt,dir_sound+name_hash+"/"+str(txt_idx)+".mp3")
  199. txt_idx+=1
  200. print("mp3 file made")
  201. #make title as image
  202. txt2image_title(name, dir_title+name_hash+".png",lang)
  203. def txt2image(content, save_target,lang='zh'):
  204. unicode_text = trim_punctuation(content)
  205. font = ''
  206. if lang=='zh':
  207. font = ImageFont.truetype(font="font/DFT_B7.ttc", size=38)
  208. else :
  209. font = ImageFont.truetype(font="font/arial.ttf", size=38)
  210. text_width, text_height = font.getsize(unicode_text)
  211. canvas = Image.new('RGBA', (700, 500), (255, 0, 0, 0) )
  212. draw = ImageDraw.Draw(canvas)
  213. text= unicode_text
  214. draw.text((5,5), text, (255, 255, 0), font)
  215. canvas.save(save_target, "PNG")
  216. def txt2image_title(content, save_target, lang='zh'):
  217. unicode_text = trim_punctuation(content)
  218. font = ''
  219. if lang=='zh':
  220. font = ImageFont.truetype(font="font/DFT_B7.ttc", size=22)
  221. else :
  222. font = ImageFont.truetype(font="font/arial.ttf", size=22)
  223. text_width, text_height = font.getsize(unicode_text)
  224. canvas = Image.new('RGBA', (510, 500), (255, 0, 0, 0) )
  225. draw = ImageDraw.Draw(canvas)
  226. text= unicode_text
  227. draw.text((5,5), text, (17, 41, 167), font)
  228. canvas.save(save_target, "PNG")
  229. def call_anchor(fileName,avatar):
  230. conn = rpyc.classic.connect("192.168.1.105",18812)
  231. ros = conn.modules.os
  232. rsys = conn.modules.sys
  233. fr=open(dir_sound+fileName+".mp3",'rb')# voice
  234. #warning!!! file my be replaced by other process
  235. fw=conn.builtins.open('/tmp/output.mp3','wb')
  236. while True:
  237. b=fr.read(1024)
  238. if b:
  239. fw.write(b)
  240. else:
  241. break
  242. fr.close()
  243. fw.close()
  244. val=random.randint(1000000,9999999)
  245. ros.chdir('/home/jared/to_video')
  246. ros.system('./p'+str(avatar)+'.sh '+str(val)+' &')
  247. while True:
  248. print('waiting...')
  249. if ros.path.exists('/tmp/results/'+str(val)):
  250. break
  251. time.sleep(5)
  252. print('waiting...')
  253. fr=conn.builtins.open('/tmp/results/'+str(val)+'.mp4','rb')
  254. fw=open(dir_anchor+fileName+".mp4",'wb')
  255. while True:
  256. b=fr.read(1024)
  257. if b:
  258. fw.write(b)
  259. else:
  260. break
  261. fr.close()
  262. fw.close()
  263. def syllable_count(word):
  264. word = word.lower()
  265. count = 0
  266. vowels = "aeiouy"
  267. if word[0] in vowels:
  268. count += 1
  269. for index in range(1, len(word)):
  270. if word[index] in vowels and word[index - 1] not in vowels:
  271. count += 1
  272. if word.endswith("e"):
  273. count -= 1
  274. if count == 0:
  275. count += 1
  276. return count
  277. def split_sentence(in_str, maxLen):
  278. re.findall(r'[\u4e00-\u9fff]+', in_str)
  279. zh_idx = []
  280. eng_idx= []
  281. for i in range(len(in_str)):
  282. if in_str[i] > u'\u4e00' and in_str[i] < u'\u9fff':
  283. zh_idx.append(i)
  284. else:
  285. eng_idx.append(i)
  286. space_index = [m.start() for m in re.finditer(' ', in_str)]
  287. for idx in space_index:
  288. eng_idx.remove(idx)
  289. eng_range_list = []
  290. for k, g in groupby(enumerate(eng_idx), lambda ix : ix[0] - ix[1]):
  291. eng_range = list(map(itemgetter(1), g))
  292. eng_range_list.append(eng_range)
  293. total_syllable = 0
  294. for i in range(len(eng_range_list)):
  295. total_syllable += (syllable_count(in_str[eng_range_list[i][0]:eng_range_list[i][-1]+1])+0.5)
  296. for i in range(len(zh_idx)):
  297. total_syllable+=1
  298. #final chchchchchc[en][en][en]
  299. #[en] is a vocabulary dict with occurence of image
  300. zh_eng_idx_list = []
  301. i = 0
  302. while i < len(in_str):
  303. if in_str[i]==' ':
  304. i+=1
  305. if i in zh_idx:
  306. zh_eng_idx_list.append(i)
  307. i+=1
  308. if i in eng_idx:
  309. for ls in eng_range_list:
  310. if i in ls:
  311. zh_eng_idx_list.append(ls)
  312. i = ls[-1]+1
  313. break
  314. zh_eng_dict_list = [{'content':'','time_ratio':0}]
  315. idx = 0
  316. current_len = 0
  317. sen_idx = 0
  318. while idx < len(zh_eng_idx_list):
  319. str_from_idx = ''
  320. sylla_cnt = 1
  321. if type(zh_eng_idx_list[idx])==type([]):
  322. str_from_idx = in_str[zh_eng_idx_list[idx][0]:zh_eng_idx_list[idx][-1]+1]+' '
  323. sylla_cnt = syllable_count(str_from_idx)
  324. else:
  325. str_from_idx = in_str[zh_eng_idx_list[idx]]
  326. if len(zh_eng_dict_list[sen_idx]['content'])+sylla_cnt>=maxLen:
  327. zh_eng_dict_list[sen_idx]['time_ratio'] = current_len/total_syllable
  328. zh_eng_dict_list.append({'content':'','time_ratio':0})
  329. sen_idx+=1
  330. current_len = 0
  331. else:
  332. current_len += sylla_cnt
  333. zh_eng_dict_list[sen_idx]['content'] += str_from_idx
  334. idx+=1
  335. total_ratio = 0
  336. for obj in zh_eng_dict_list:
  337. total_ratio+=obj['time_ratio']
  338. zh_eng_dict_list[-1]['time_ratio'] = 1-total_ratio
  339. return zh_eng_dict_list
  340. def parse_script(file_path,gt_list):
  341. with open(file_path, 'r',encoding="utf-8") as f:
  342. raw_lines = [line.strip() for line in f]
  343. lines = adjustSub_by_text_similarity(gt_list,raw_lines)
  344. text_parser = parser()
  345. #make dict
  346. dict_list = []
  347. for idx in range(len(lines)):
  348. script={}
  349. rep_ls = text_parser.replace_list(lines[idx])
  350. line_content = lines[idx]
  351. for reptxt in rep_ls:
  352. line_content = line_content.replace(reptxt,'')
  353. if len(rep_ls)!=0:
  354. script['image_idx'] = int(rep_ls[0].replace('{','').replace('}',''))
  355. script['content'] = line_content
  356. time_raw = raw_lines[idx * 4 +1 ].split(' --> ')
  357. start = time_raw[0].split(':')
  358. stop = time_raw[1].split(':')
  359. script['start'] = float(start[0])*3600 + float(start[1])*60 + float(start[2].replace(',','.'))
  360. script['stop'] = float(stop[0])*3600 + float(stop[1])*60 + float(stop[2].replace(',','.'))
  361. dict_list.append(script)
  362. #merge duplicated sentences
  363. skip_list = []
  364. script_not_dup_list = []
  365. for idx in range(len(dict_list)):
  366. if idx not in skip_list:
  367. dup_list = []
  368. found = 0
  369. for idx_inner in range(len(dict_list)):
  370. if dict_list[idx_inner]['content'] == dict_list[idx]['content'] and idx <= idx_inner:
  371. dup_list.append(idx_inner)
  372. skip_list.append(idx_inner)
  373. found += 1
  374. if found != 0 and dict_list[idx_inner]['content']!=dict_list[idx]['content'] and idx <= idx_inner:
  375. found = 0
  376. break
  377. for dup_idx in dup_list:
  378. if dup_idx == min(dup_list):
  379. dict_list[dup_idx]['type'] = 'lead_sentence'
  380. else:
  381. dict_list[dup_idx]['type'] = 'duplicated'
  382. dict_list[dup_list[0]]['stop'] = dict_list[dup_list[-1]]['stop']
  383. if dict_list[idx]['type'] == 'lead_sentence':
  384. script_not_dup_list.append(dict_list[idx])
  385. new_idx = 0
  386. splitted_dict = []
  387. for dic in script_not_dup_list:
  388. dic_idx = 0
  389. accumulated_duration = 0
  390. duration = dic['stop']-dic['start']
  391. if duration > 5:
  392. print('fuck',dic)
  393. for sub_dic in split_sentence(dic['content'],13):
  394. new_dic = {}
  395. new_dic['index'] = new_idx
  396. if 'image_idx' in dic:
  397. new_dic['image_obj'] = {'start':dic['start'],'idx':dic['image_idx']}
  398. new_idx+=1
  399. ind_duration = duration * sub_dic['time_ratio']
  400. new_dic['start'] = dic['start'] + accumulated_duration
  401. accumulated_duration += ind_duration
  402. new_dic['content'] = sub_dic['content']
  403. new_dic['duration'] = ind_duration*0.7
  404. splitted_dict.append(new_dic)
  405. return splitted_dict
  406. def adjustSub_by_text_similarity(gts_in,gens_raw):
  407. #call by value only
  408. gts = gts_in[:]
  409. text_parser = parser()
  410. for i in range(len(gts)):
  411. rep_ls = text_parser.replace_list(gts[i])
  412. for reptxt in rep_ls:
  413. gts[i] = gts[i].replace(reptxt,'')
  414. gens = []
  415. for idx in range(int((len(gens_raw)+1)/4)):
  416. gens.append(gens_raw[idx*4+2])
  417. combine2 = [''.join([i,j]) for i,j in zip(gts, gts[1:])]
  418. combine3 = [''.join([i,j,k]) for i,j,k in zip(gts, gts[1:], gts[2:])]
  419. alls = gts + combine2 + combine3
  420. adjusted = [None]*len(gens)
  421. duplicated_list = []
  422. for idx in range(len(gens)):
  423. match_text = difflib.get_close_matches(gens[idx], alls, cutoff=0.1)
  424. if len(match_text) != 0:
  425. if match_text[0] not in duplicated_list:
  426. adjusted[idx] = match_text[0]
  427. duplicated_list.append(match_text[0])
  428. else:
  429. if match_text[0] == adjusted[idx-1]:
  430. adjusted[idx] = match_text[0]
  431. else:
  432. found = 0
  433. for mt in match_text:
  434. if mt not in duplicated_list:
  435. adjusted[idx] = mt
  436. found += 1
  437. break
  438. if found ==0:
  439. adjusted[idx] = ' '
  440. else :
  441. adjusted[idx] = ' '
  442. combine2_tag = [''.join([i,j]) for i,j in zip(gts_in, gts_in[1:])]
  443. combine3_tag = [''.join([i,j,k]) for i,j,k in zip(gts_in, gts_in[1:], gts_in[2:])]
  444. alls_tag = gts_in + combine2_tag + combine3_tag
  445. for idx in range(len(adjusted)):
  446. match_text = difflib.get_close_matches(adjusted[idx], alls_tag, cutoff=0.1)
  447. adjusted[idx] = match_text[0]
  448. return adjusted
  449. def trim_punctuation(s):
  450. pat_block = u'[^\u4e00-\u9fff0-9a-zA-Z]+';
  451. pattern = u'([0-9]+{0}[0-9]+)|{0}'.format(pat_block)
  452. res = re.sub(pattern, lambda x: x.group(1) if x.group(1) else u" " ,s)
  453. return res
  454. def splitter(s):
  455. for sent in re.findall(u'[^!?,。\!\?]+[!? 。\!\?]?', s, flags=re.U):
  456. yield sent
  457. def split_by_pun(s):
  458. res = list(splitter(s))
  459. return res
  460. def generate_subtitle_image_from_dict(name_hash, sub_dict):
  461. for script in sub_dict:
  462. sv_path = dir_subtitle + name_hash + '/' + str(script['index'])+'.png'
  463. sub = script['content']
  464. txt2image(sub,sv_path)
  465. def generate_subtitle_image(name_hash,text_content):
  466. img_list = [None]*len(text_content)
  467. for idx in range(len(text_content)):
  468. img_list[idx]=[]
  469. senList = split_by_pun(text_content[idx])
  470. for inner_idx in range(len(senList)):
  471. sv_path = dir_subtitle + name_hash +'/'+str(idx)+ str(inner_idx) +'.png'
  472. sub = senList[inner_idx]
  473. txt2image(sub,sv_path)
  474. img_list[idx]+=[{"count":len(sub),"path":sv_path}]
  475. return img_list
  476. def generate_subtitle_image_ENG(name_hash,text_content):
  477. img_list = [None]*len(text_content)
  478. for idx in range(len(text_content)):
  479. sv_path = dir_subtitle + name_hash +'/'+str(idx)+'.png'
  480. sub = text_content[idx]
  481. txt2image(sub, sv_path,lang='eng')
  482. img_list[idx] = sv_path
  483. return img_list
  484. def video_writer_init(path):
  485. w = openshot.FFmpegWriter(path)
  486. w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
  487. w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
  488. openshot.Fraction(1, 1), False, False, 3000000)
  489. return w
  490. def video_gen(name_hash,name,text_content, image_urls,multiLang,avatar):
  491. file_prepare_long(name, name_hash, text_content,image_urls,multiLang)
  492. for fname in range(len(text_content)):
  493. call_anchor(name_hash+"/"+str(fname),avatar)
  494. print('called............................................')
  495. ck=cKey(0,254,0,270)
  496. ck_anchor=cKey(0,255,1,320)
  497. t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
  498. t.Open()
  499. main_timer = 0
  500. LOGO_OP = openshot.FFmpegReader(dir_video+"LOGO_OP_4.mp4")
  501. LOGO_OP.Open() # Open the reader
  502. head_duration = LOGO_OP.info.duration
  503. LOGO_OP_clip = video_photo_clip(vid=LOGO_OP,layer=4,position=0,end=head_duration
  504. ,location_y=-0.03,scale_x=0.8,scale_y=0.704)
  505. t.AddClip(LOGO_OP_clip)
  506. bg_head = openshot.FFmpegReader(dir_video+"complete_head_aispokesgirl.mp4")
  507. bg_head.Open()
  508. bg_head_clip = video_photo_clip(vid=bg_head,layer=2,position=0,end=LOGO_OP.info.duration,ck=ck)
  509. t.AddClip(bg_head_clip)
  510. main_timer += head_duration
  511. bg_head.Close()
  512. LOGO_OP.Close()
  513. anchor = openshot.FFmpegReader(dir_anchor+name_hash+"/0.mp4")
  514. anchor.Open()
  515. #anchor_clip = video_photo_clip(vid=anchor,layer=4,scale_x=0.65,scale_y=0.65,
  516. # location_x=0.35,location_y=0.25,position=main_timer, end=anchor.info.duration,ck=ck_anchor,audio=False)
  517. #t.AddClip(anchor_clip)
  518. speech = openshot.FFmpegReader(dir_sound+name_hash+"/0.mp3")
  519. speech.Open()
  520. speech_clip = openshot.Clip(speech)
  521. speech_clip.Position(main_timer)
  522. speech_clip.End(anchor.info.duration)
  523. t.AddClip(speech_clip)
  524. main_timer += anchor.info.duration
  525. anchor.Close()
  526. speech.Close()
  527. LOGO_ED = openshot.FFmpegReader(dir_video+"LOGO_ED.avi")
  528. LOGO_ED.Open()
  529. LOGO_ED_clip = video_photo_clip(vid=LOGO_ED,layer=4,position=main_timer,end=LOGO_ED.info.duration
  530. ,location_x=0.005,location_y=-0.031, scale_x=0.8,scale_y=0.6825)
  531. t.AddClip(LOGO_ED_clip)
  532. main_timer += LOGO_ED.info.duration
  533. LOGO_ED.Close()
  534. bg = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  535. bg.Open()
  536. bg_times = math.floor(main_timer/bg.info.duration)
  537. left_time = (main_timer) % bg.info.duration
  538. bg_clip_list = [None] * bg_times
  539. bg_list = [None] * bg_times
  540. bg.Close()
  541. bg_timer = head_duration
  542. for idx in range(bg_times):
  543. bg_list[idx] = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  544. bg_list[idx].Open()
  545. bg_clip_list[idx] = video_photo_clip(bg_list[idx],layer=2,position=bg_timer,end=bg_list[idx].info.duration,ck=ck)
  546. t.AddClip(bg_clip_list[idx])
  547. bg_timer += bg_list[idx].info.duration
  548. bg_list[idx].Close()
  549. bg_left = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  550. bg_left.Open()
  551. bg_left_clip = video_photo_clip(bg_left,layer=2,position=bg_timer,end=left_time,ck=ck)
  552. t.AddClip(bg_left_clip)
  553. bg_left.Close()
  554. title = openshot.QtImageReader(dir_title+name_hash+".png")
  555. title.Open() # Open the reader
  556. title_clip = video_photo_clip(vid=title, layer=4,location_x=-0.047, location_y=0.801,position=0,end=head_duration+main_timer)
  557. t.AddClip(title_clip)
  558. w = video_writer_init(tmp_video_dir+name_hash+"raw.mp4")
  559. w.Open()
  560. frames = int(t.info.fps)*int(main_timer)
  561. for n in range(frames):
  562. f=t.GetFrame(n)
  563. w.WriteFrame(f)
  564. t.Close()
  565. w.Close()
  566. print(name+"RAW DONE : www.choozmo.com:8168/"+tmp_video_dir+name_hash+"raw.mp4")
  567. #start adding sub
  568. #add sub
  569. Ctr_Autosub.init()
  570. Ctr_Autosub.generate_subtitles(tmp_video_dir+name_hash+"raw.mp4",'zh',listener_progress,output=tmp_video_dir+name_hash+"script.txt",concurrency=DEFAULT_CONCURRENCY,subtitle_file_format=DEFAULT_SUBTITLE_FORMAT)
  571. sub_dict = parse_script(tmp_video_dir+name_hash+"script.txt",split_by_pun(text_content[0]))
  572. for subd in sub_dict:
  573. print(subd)
  574. generate_subtitle_image_from_dict(name_hash, sub_dict)
  575. #sv_path = dir_subtitle + name_hash + '/' + str(script['index'])+'.png'
  576. t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
  577. t.Open()
  578. raw = openshot.FFmpegReader(tmp_video_dir+name_hash+"raw.mp4")
  579. raw.Open()
  580. raw_clip = video_photo_clip(vid=raw,layer=2,position=0, end=raw.info.duration)
  581. t.AddClip(raw_clip)
  582. sub_img_list = [None] * len(sub_dict)
  583. sub_clip_list = [None] * len(sub_dict)
  584. for sub_obj in sub_dict:
  585. idx = int(sub_obj['index'])
  586. sub_img_list[idx] = openshot.QtImageReader(dir_subtitle + name_hash + '/' + str(idx)+'.png')
  587. sub_img_list[idx].Open()
  588. #if sub_obj['duration']>3:
  589. # print('warning')
  590. #print('start:',sub_obj['start'],', duration :', sub_obj['duration'],' content',sub_obj['content'],'idx:',sub_obj['index'])
  591. sub_clip_list[idx] = video_photo_clip(vid=sub_img_list[idx], layer=6,location_x=0.069, location_y=0.89,position=sub_obj['start'],end=math.ceil(sub_obj['duration']))
  592. t.AddClip(sub_clip_list[idx])
  593. sub_img_list[idx].Close()
  594. tp = parser()
  595. img_dict_ls = tp.image_clip_info(sub_dict)
  596. img_clip_list = [None]*len(listdir(dir_photo+name_hash))
  597. img_list = [None]*len(img_clip_list)
  598. img_file_ls = listdir(dir_photo+name_hash)
  599. print(img_file_ls)
  600. print(img_dict_ls)
  601. for img_idx in range(len(img_file_ls)):
  602. img_list[img_idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+img_file_ls[img_idx])
  603. img_list[img_idx].Open()
  604. img_clip_list[img_idx] = video_photo_clip(vid=img_list[img_idx],layer=3
  605. ,scale_x=0.81,scale_y=0.68,location_y=-0.03,position=img_dict_ls[img_idx]['start'],end=img_dict_ls[img_idx]['duration'],audio=False)
  606. t.AddClip(img_clip_list[img_idx])
  607. img_list[img_idx].Close()
  608. anchor = openshot.FFmpegReader(dir_anchor+name_hash+"/0.mp4")
  609. anchor.Open()
  610. anchor_clip = video_photo_clip(vid=anchor,layer=4,scale_x=0.65,scale_y=0.65,
  611. location_x=0.35,location_y=0.25,position=head_duration, end=anchor.info.duration,ck=ck_anchor,audio=False)
  612. t.AddClip(anchor_clip)
  613. w = video_writer_init(tmp_video_dir+name_hash+".mp4")
  614. w.Open()
  615. frames = int(t.info.fps)*int(main_timer)
  616. for n in range(frames):
  617. f=t.GetFrame(n)
  618. w.WriteFrame(f)
  619. t.Close()
  620. w.Close()
  621. path = tmp_video_dir+name_hash+"script.txt"
  622. f = open(path, 'r')
  623. print(f.read())
  624. f.close()
  625. #os.remove(tmp_video_dir+name_hash+"raw.mp4")
  626. #os.remove(tmp_video_dir+name_hash+"script.txt")
  627. print(name+"ALL DONE : www.choozmo.com:8168/"+video_sub_folder+name_hash+"raw.mp4")
  628. Ctr_Autosub.init()
  629. Ctr_Autosub.generate_subtitles(tmp_video_dir+name_hash+".mp4",'zh',listener_progress,output=tmp_video_dir+name_hash+"script.txt",concurrency=DEFAULT_CONCURRENCY,subtitle_file_format=DEFAULT_SUBTITLE_FORMAT)
  630. path = tmp_video_dir+name_hash+"script.txt"
  631. f = open(path, 'r')
  632. print(f.read())
  633. f.close()
  634. def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar):
  635. print(os.getcwd())
  636. print('sub image made')
  637. print(multiLang)
  638. file_prepare(name, name_hash, text_content,image_urls,multiLang)
  639. sub_list=generate_subtitle_image(name_hash,text_content)
  640. for fname in range(len(text_content)):
  641. call_anchor(name_hash+"/"+str(fname),avatar)
  642. print('step finish')
  643. print('called............................................')
  644. ck=cKey(0,254,0,270)
  645. ck_anchor=cKey(0,255,1,320)
  646. duration = 0
  647. #average layer level is 3
  648. t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
  649. t.Open()
  650. main_timer = 0
  651. LOGO_OP = openshot.FFmpegReader(dir_video+"LOGO_OP_4.mp4")
  652. LOGO_OP.Open() # Open the reader
  653. LOGO_OP_clip = video_photo_clip(vid=LOGO_OP,layer=4,position=0,end=LOGO_OP.info.duration
  654. ,location_y=-0.03,scale_x=0.8,scale_y=0.704)
  655. t.AddClip(LOGO_OP_clip)
  656. bg_head = openshot.FFmpegReader(dir_video+"complete_head_aispokesgirl.mp4")
  657. bg_head.Open()
  658. bg_head_clip = video_photo_clip(vid=bg_head,layer=2,position=0,end=LOGO_OP.info.duration,ck=ck)
  659. t.AddClip(bg_head_clip)
  660. main_timer += LOGO_OP.info.duration
  661. head_duration = LOGO_OP.info.duration
  662. bg_head.Close()
  663. LOGO_OP.Close()
  664. clip_duration=0
  665. photo_clip_list = [None]*len(text_content)
  666. img_list = [None]*len(text_content)
  667. anchor_clip_list = [None] * len(text_content)
  668. anchor_list = [None] * len(text_content)
  669. audio_clip_list = [None] * len(text_content)
  670. audio_list = [None] * len(text_content)
  671. sub_clip_list = [None] * len(text_content)
  672. sub_img_list = [None] * len(text_content)
  673. idx = 0
  674. for p in listdir(dir_photo+name_hash):
  675. anchor_list[idx] = openshot.FFmpegReader(dir_anchor+name_hash+"/"+str(idx)+".mp4")
  676. clip_duration = anchor_list[idx].info.duration
  677. anchor_list[idx].Open()
  678. anchor_clip_list[idx] = video_photo_clip(vid=anchor_list[idx],layer=4,scale_x=0.65,scale_y=0.65,
  679. location_x=0.35,location_y=0.25,position=main_timer, end=clip_duration,ck=ck_anchor,audio=False)
  680. t.AddClip(anchor_clip_list[idx])
  681. img_list[idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+p)
  682. img_list[idx].Open()
  683. photo_clip_list[idx] = video_photo_clip(vid=img_list[idx],layer=3
  684. ,scale_x=0.81,scale_y=0.68,location_y=-0.03,position=main_timer,end=clip_duration,audio=False)
  685. t.AddClip(photo_clip_list[idx])
  686. img_list[idx].Close()
  687. audio_list[idx] = openshot.FFmpegReader(dir_sound+name_hash+"/"+str(idx)+".mp3")
  688. audio_list[idx].Open()
  689. audio_clip_list[idx] = openshot.Clip(audio_list[idx])
  690. audio_clip_list[idx].Position(main_timer)
  691. audio_clip_list[idx].End(clip_duration)
  692. t.AddClip(audio_clip_list[idx])
  693. img_list[idx].Close()
  694. anchor_list[idx].Close()
  695. audio_list[idx].Close()
  696. sub_img_list[idx] = [None] * len(sub_list[idx])
  697. sub_clip_list[idx] = [None] * len(sub_list[idx])
  698. sub_timer = 0
  699. for sub_idx in range(len(sub_list[idx])):
  700. sub_img_list[idx][sub_idx] = openshot.QtImageReader(sub_list[idx][sub_idx]['path'])
  701. sub_img_list[idx][sub_idx].Open()
  702. sub_duration = 0.205*sub_list[idx][sub_idx]['count']
  703. sub_clip_list[idx][sub_idx] = video_photo_clip(vid=sub_img_list[idx][sub_idx], layer=6,location_x=0.069, location_y=0.89,position=main_timer+sub_timer,end=sub_duration)
  704. t.AddClip(sub_clip_list[idx][sub_idx])
  705. sub_img_list[idx][sub_idx].Close()
  706. sub_timer += sub_duration
  707. print(sub_list[idx][sub_idx]['path'])
  708. main_timer += clip_duration
  709. idx+=1
  710. LOGO_ED = openshot.FFmpegReader(dir_video+"LOGO_ED.avi")
  711. LOGO_ED.Open()
  712. LOGO_ED_clip = video_photo_clip(vid=LOGO_ED,layer=4,position=main_timer,end=LOGO_ED.info.duration+2
  713. ,location_x=0.005,location_y=-0.031
  714. ,scale_x=0.8,scale_y=0.6825)
  715. t.AddClip(LOGO_ED_clip)
  716. ED_duration = LOGO_ED.info.duration
  717. LOGO_ED.Close()
  718. bg = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  719. bg.Open()
  720. bg_times = math.floor(main_timer+ED_duration/bg.info.duration)
  721. left_time = (main_timer+ED_duration) % bg.info.duration
  722. bg_clip_list = [None] * bg_times
  723. bg_list = [None] * bg_times
  724. bg.Close()
  725. bg_timer = head_duration
  726. for idx in range(bg_times):
  727. bg_list[idx] = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  728. bg_list[idx].Open()
  729. bg_clip_list[idx] = video_photo_clip(bg_list[idx],layer=2,position=bg_timer
  730. ,end=bg_list[idx].info.duration,ck=ck)
  731. t.AddClip(bg_clip_list[idx])
  732. bg_timer += bg_list[idx].info.duration
  733. bg_list[idx].Close()
  734. bg_left = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  735. bg_left.Open()
  736. bg_left_clip = video_photo_clip(bg_left,layer=2,position=bg_timer,end=left_time,ck=ck)
  737. t.AddClip(bg_left_clip)
  738. bg_left.Close()
  739. title = openshot.QtImageReader(dir_title+name_hash+".png")
  740. title.Open() # Open the reader
  741. title_clip = video_photo_clip(vid=title, layer=4,location_x=-0.047, location_y=0.801,position=0,end=head_duration+main_timer)
  742. t.AddClip(title_clip)
  743. ####start building
  744. w = openshot.FFmpegWriter(tmp_video_dir+name_hash+".mp4")
  745. w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
  746. w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
  747. openshot.Fraction(1, 1), False, False, 3000000)
  748. w.Open()
  749. #may change duration into t.info.duration
  750. frames = int(t.info.fps)*int(head_duration+main_timer+ED_duration)
  751. for n in range(frames):
  752. f=t.GetFrame(n)
  753. w.WriteFrame(f)
  754. #notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
  755. t.Close()
  756. w.Close()
  757. print("video at : www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
  758. def anchor_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar):
  759. file_prepare(name, name_hash, text_content,image_urls,'eng')
  760. sub_list=generate_subtitle_image_ENG(name_hash,sub_titles)
  761. for fname in range(len(text_content)):
  762. call_anchor(name_hash+"/"+str(fname),avatar)
  763. print('step finish')
  764. print('called............................................')
  765. ck=cKey(0,254,0,270)
  766. ck_anchor=cKey(0,255,1,320)
  767. duration = 0
  768. #average layer level is 3
  769. t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
  770. t.Open()
  771. main_timer = 0
  772. #add logo
  773. LOGO_OP = openshot.FFmpegReader(dir_video+"LOGO_OP_4.mp4")
  774. LOGO_OP.Open() # Open the reader
  775. LOGO_OP_clip = video_photo_clip(vid=LOGO_OP,layer=4,position=0,end=LOGO_OP.info.duration
  776. ,location_y=-0.03,scale_x=0.8,scale_y=0.704)
  777. t.AddClip(LOGO_OP_clip)
  778. #add background video (head is different)
  779. bg_head = openshot.FFmpegReader(dir_video+"complete_head_aispokesgirl.mp4")
  780. bg_head.Open()
  781. bg_head_clip = video_photo_clip(vid=bg_head,layer=2,position=0,end=LOGO_OP.info.duration,ck=ck)
  782. t.AddClip(bg_head_clip)
  783. main_timer += LOGO_OP.info.duration
  784. head_duration = LOGO_OP.info.duration
  785. bg_head.Close()
  786. LOGO_OP.Close()
  787. #prepare empty list
  788. clip_duration=0
  789. photo_clip_list = [None]*len(text_content)
  790. img_list = [None]*len(text_content)
  791. anchor_clip_list = [None] * len(text_content)
  792. anchor_list = [None] * len(text_content)
  793. audio_clip_list = [None] * len(text_content)
  794. audio_list = [None] * len(text_content)
  795. sub_clip_list = [None] * len(text_content)
  796. #openshot image holder
  797. sub_img_list = [None] * len(text_content)
  798. idx = 0
  799. for p in listdir(dir_photo+name_hash):
  800. anchor_list[idx] = openshot.FFmpegReader(dir_anchor+name_hash+"/"+str(idx)+".mp4")
  801. clip_duration = anchor_list[idx].info.duration
  802. anchor_list[idx].Open()
  803. anchor_clip_list[idx] = video_photo_clip(vid=anchor_list[idx],layer=4,scale_x=0.65,scale_y=0.65,
  804. location_x=0.35,location_y=0.25,position=main_timer, end=clip_duration,ck=ck_anchor,audio=False)
  805. t.AddClip(anchor_clip_list[idx])
  806. #insert image
  807. img_list[idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+p)
  808. img_list[idx].Open()
  809. photo_clip_list[idx] = video_photo_clip(vid=img_list[idx],layer=3
  810. ,scale_x=0.81,scale_y=0.68,location_y=-0.03,position=main_timer,end=clip_duration,audio=False)
  811. t.AddClip(photo_clip_list[idx])
  812. img_list[idx].Close()
  813. #insert audio (speech)
  814. audio_list[idx] = openshot.FFmpegReader(dir_sound+name_hash+"/"+str(idx)+".mp3")
  815. audio_list[idx].Open()
  816. audio_clip_list[idx] = openshot.Clip(audio_list[idx])
  817. audio_clip_list[idx].Position(main_timer)
  818. audio_clip_list[idx].End(clip_duration)
  819. t.AddClip(audio_clip_list[idx])
  820. #insert subtitle
  821. sub_img_list[idx] = openshot.QtImageReader(sub_list[idx])
  822. sub_img_list[idx].Open()
  823. sub_clip_list[idx] = video_photo_clip(vid=sub_img_list[idx], layer=6,location_x=0.069, location_y=0.89,position=main_timer,end=clip_duration)
  824. t.AddClip(sub_clip_list[idx])
  825. img_list[idx].Close()
  826. anchor_list[idx].Close()
  827. audio_list[idx].Close()
  828. sub_img_list[idx].Close()
  829. main_timer += clip_duration
  830. idx+=1
  831. LOGO_ED = openshot.FFmpegReader(dir_video+"ED_ENG.mp4")
  832. LOGO_ED.Open()
  833. LOGO_ED_clip = video_photo_clip(vid=LOGO_ED,layer=4,position=main_timer,end=LOGO_ED.info.duration+2
  834. ,location_x=0.005,location_y=-0.031
  835. ,scale_x=0.8,scale_y=0.6825)
  836. t.AddClip(LOGO_ED_clip)
  837. ED_duration = LOGO_ED.info.duration
  838. LOGO_ED.Close()
  839. bg = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  840. bg.Open()
  841. bg_times = math.floor(main_timer+ED_duration/bg.info.duration)
  842. left_time = (main_timer+ED_duration) % bg.info.duration
  843. bg_clip_list = [None] * bg_times
  844. bg_list = [None] * bg_times
  845. bg.Close()
  846. bg_timer = head_duration
  847. for idx in range(bg_times):
  848. bg_list[idx] = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  849. bg_list[idx].Open()
  850. bg_clip_list[idx] = video_photo_clip(bg_list[idx],layer=2,position=bg_timer
  851. ,end=bg_list[idx].info.duration,ck=ck)
  852. t.AddClip(bg_clip_list[idx])
  853. bg_timer += bg_list[idx].info.duration
  854. bg_list[idx].Close()
  855. bg_left = openshot.FFmpegReader(dir_video+"complete_double_aispokesgirl.mp4")
  856. bg_left.Open()
  857. bg_left_clip = video_photo_clip(bg_left,layer=2,position=bg_timer,end=left_time,ck=ck)
  858. t.AddClip(bg_left_clip)
  859. bg_left.Close()
  860. title = openshot.QtImageReader(dir_title+name_hash+".png")
  861. title.Open() # Open the reader
  862. title_clip = video_photo_clip(vid=title, layer=4,location_x=-0.047, location_y=0.801,position=0,end=head_duration+main_timer)
  863. t.AddClip(title_clip)
  864. ####start building
  865. w = openshot.FFmpegWriter(tmp_video_dir+name_hash+".mp4")
  866. w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
  867. w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
  868. openshot.Fraction(1, 1), False, False, 3000000)
  869. w.Open()
  870. #may change duration into t.info.duration
  871. frames = int(t.info.fps)*int(head_duration+main_timer+ED_duration)
  872. for n in range(frames):
  873. f=t.GetFrame(n)
  874. w.WriteFrame(f)
  875. #notify_group(name+"(ENG)的影片已經產生完成囉! www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
  876. t.Close()
  877. w.Close()
  878. print("video at : www.choozmo.com:8168/"+video_sub_folder+name_hash+".mp4")
  879. #line notifs
  880. import pyttsx3
  881. def make_speech(text):
  882. engine = pyttsx3.init()
  883. #voices = engine.getProperty('voices')
  884. engine.setProperty('voice', 'Mandarin')
  885. engine.save_to_file(text, '/app/speech.mp3')
  886. engine.runAndWait()
  887. class video_service(rpyc.Service):
  888. def exposed_call_video(self,name_hash,name,text_content, image_urls,multiLang,avatar):
  889. print('ML:'+str(multiLang))
  890. anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar)
  891. def exposed_call_video_eng(self,name_hash,name,text_content, image_urls,sub_titles,avatar):
  892. anchor_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar)
  893. def exposed_call_video_gen(self,name_hash,name,text_content, image_urls,multiLang,avatar):
  894. print('ML:'+str(multiLang))#this is long video version,
  895. video_gen(name_hash,name,text_content, image_urls,multiLang,avatar)
  896. def exposed_make_speech(self,text):
  897. make_speech(text)
  898. from rpyc.utils.server import ThreadedServer
  899. t = ThreadedServer(video_service, port=8858)
  900. print('service started')
  901. t.start()