openshot_video_generator.py 38 KB

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