import rpyc
import random
import time
import codecs
import sys
import os
from gtts import gTTS

fr=codecs.open('/tmp/script.txt','r','utf-8')
lines=fr.readlines()
fr.close()
txt=lines[0].strip()

tts = gTTS(txt, lang='zh-tw')
tts.save('/tmp/ok2.mp3')



val=random.randint(1000000,9999999)
os.chdir('/home/jared/Wav2Lip-master')
os.system('./proc.sh '+str(val)+' &')


while True:
    print('waiting...')
    if os.path.exists('/tmp/results/'+str(val)):
        break
    time.sleep(5)
    print('waiting...')



os.system('cp /home/jared/Wav2Lip-master/results/result_voice.mp4 /tmp')
os.chdir('/home/jared/tests/libopenshot')
os.system('python3 jaredtest.py')
os.system('cp /tmp/out.mp4 /var/www/html/out.mp4')
os.system('telegram-send "video is ready, http://139.162.121.30:54321/out.mp4"')
