Parcourir la source

Merge branch 'master' of http://git.choozmo.com:3000/choozmo/AI_Anchor_2

huai-sian il y a 3 ans
Parent
commit
5c9b92adab

+ 3 - 3
OpenshotService/openshot_video_generator.py

@@ -793,9 +793,9 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,multiLang,avatar,fre
         anchor_list[idx].Open()
         anchor_clip_list[idx] = video_photo_clip(vid=anchor_list[idx],layer=4,scale_x=0.65,scale_y=0.65,
                 location_x=0.35,location_y=0.25,position=main_timer, end=clip_duration,ck=ck_anchor,audio=False)
-        if avatar!=18:
-            print('avatar is ', avatar)
-            t.AddClip(anchor_clip_list[idx])
+        
+        print('avatar is ', avatar)
+        t.AddClip(anchor_clip_list[idx])
         
 
         img_list[idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+p)

BIN
api/__pycache__/gSlide.cpython-39.pyc


BIN
api/__pycache__/mailer.cpython-39.pyc


BIN
api/__pycache__/main.cpython-39.pyc


+ 9 - 8
api/main.py

@@ -44,13 +44,14 @@ import gSlide
 import aiofiles
 import json
 import util.user
-from routers import userRoute
+from routers import userRoute, toolAvatarVoiceOnly
 #https://www.choozmo.com:8887/verify_email?code=16370312713065429 => 
 #https://video.choozmo.com/verify_email.html?code=16370312713065429
 pymysql.install_as_MySQLdb()
 
 app = FastAPI()
 app.include_router(userRoute.router)
+app.include_router(toolAvatarVoiceOnly.router)
 db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
 print("db loaded")
 mode = 'run'
@@ -697,7 +698,7 @@ async def make_anchor_video_eng(req:util.models.request_eng,token: str = Depends
     if 6 in util.user.get_user_role_list(user_id):
         freeTrial = 1
     print(freeTrial)
-    x = threading.Thread(target=gen_video_queue_eng, args=(name_hash,req.name, req.text_content, req.image_urls,req.sub_titles,int(req.avatar),video_id,freeTrial))
+    x = threading.Thread(target=gen_video_queue_eng, args=(name_hash,req.name, req.text_content, req.image_urls,req.sub_titles,int(req.avatar),video_id,user_id,freeTrial))
     x.start()
      
     if first(db.query('SELECT COUNT(1) FROM video_queue'))['COUNT(1)'] >= 3:
@@ -727,7 +728,7 @@ async def make_anchor_video_eng(req:util.models.request_eng):
  
     video_id = save_history(req,name_hash, -1)
     freeTrial = 1
-    x = threading.Thread(target=gen_video_queue_eng, args=(name_hash,req.name, req.text_content, req.image_urls,req.sub_titles,int(req.avatar),video_id,freeTrial))
+    x = threading.Thread(target=gen_video_queue_eng, args=(name_hash,req.name, req.text_content, req.image_urls,req.sub_titles,int(req.avatar),video_id,-1,freeTrial))
     x.start()
      
     if first(db.query('SELECT COUNT(1) FROM video_queue'))['COUNT(1)'] >= 3:
@@ -757,7 +758,7 @@ async def make_anchor_video_eng(req:util.models.request_eng):
  
     video_id = save_history(req,name_hash, -1)
     freeTrial = 1
-    x = threading.Thread(target=gen_video_queue_eng, args=(name_hash,req.name, req.text_content, req.image_urls,req.sub_titles,int(req.avatar),video_id,freeTrial))
+    x = threading.Thread(target=gen_video_queue_eng, args=(name_hash,req.name, req.text_content, req.image_urls,req.sub_titles,int(req.avatar),video_id,-1,freeTrial))
     x.start()
      
     if first(db.query('SELECT COUNT(1) FROM video_queue'))['COUNT(1)'] >= 3:
@@ -1141,7 +1142,7 @@ def gen_video_queue(name_hash,name,text_content, image_urls,avatar,multiLang,vid
         db.close()
     db.close()
 
-def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avatar,video_id,freeTrial):
+def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avatar,video_id,user_id,freeTrial):
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
     if name_hash == 'keepRunning':
         if first(db.query('SELECT COUNT(1) FROM video_queue where video_type="eng"'))['COUNT(1)'] == 0:
@@ -1164,7 +1165,7 @@ def gen_video_queue_eng(name_hash,name,text_content, image_urls,sub_titles,avata
         subtitles_seperate_by_dot = subtitles_seperate_by_dot[:-1]
 
         db['video_queue'].insert({'name_hash':name_hash,'name':name,'text_content':txt_content_seperate_by_dot
-        ,'image_urls':img_urls_seperate_by_dot,'subtitles':subtitles_seperate_by_dot,'multiLang':multiLang,'video_type':'eng','avatar':avatar,'timestamp':time_stamp,'freeTrial':freeTrial})
+        ,'image_urls':img_urls_seperate_by_dot,'subtitles':subtitles_seperate_by_dot,'video_type':'eng','avatar':avatar,'timestamp':time_stamp,'freeTrial':freeTrial})
     while True:
         db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
         if first(db.query('SELECT * FROM video_queue_status'))['status'] == 1:#only one row in this table, which is the id 1 one
@@ -1325,10 +1326,10 @@ def db_check():
 
 
 def clear_video_queue():
-    x = threading.Thread(target=gen_video_queue_eng, args=('keepRunning','', '', '','','',''))
+    x = threading.Thread(target=gen_video_queue_eng, args=('keepRunning','', '', '','','','',-1,0))
     x.start()
 
-    x2 = threading.Thread(target=gen_video_queue, args=('keepRunning','', '', '','','','',''))
+    x2 = threading.Thread(target=gen_video_queue, args=('keepRunning','', '', '','','','',-1,0))
     x2.start()
 
     x3 = threading.Thread(target=gen_video_long_queue, args=('keepRunning','', '', '','','','',''))

BIN
api/routers/__pycache__/toolAvatarVoiceOnly.cpython-39.pyc


BIN
api/routers/__pycache__/userRoute.cpython-39.pyc


+ 106 - 0
api/routers/toolAvatarVoiceOnly.py

@@ -0,0 +1,106 @@
+from fastapi import APIRouter
+from pydantic import BaseModel
+from gtts import gTTS
+import ffmpy
+
+import random
+from typing import Optional
+from fastapi.staticfiles import StaticFiles
+from fastapi import FastAPI,File,Request,Response
+import util,os, math, time
+from pydantic import BaseModel
+from fastapi.templating import Jinja2Templates
+import queue, shutil
+import threading
+import rpyc
+import requests
+
+q = queue.Queue()
+router = APIRouter()
+
+class text_in(BaseModel):
+    text: str
+    lang: int #0:eng 1:zh
+    avatar: int
+
+dir_sound = ''
+dir_anchor = ''
+tool_dest = '/var/www/html/tools/'
+
+@router.post("/get_material/", tags=["tools"])
+async def get_material(text_in: text_in):
+    x = threading.Thread(target=memberOfQueue, args=(text_in.text,text_in.lang,text_in.avatar))
+    x.start()
+    return {'msg':'Pleas wait'}
+
+def memberOfQueue(txt,lang,avatar):
+    q.put(compose(txt,lang,avatar))
+
+def compose(txt,lang,avatar):
+    name_hash = str(time.time()).replace('.','')
+    makeMP3(name_hash,txt,lang)
+    call_anchor(name_hash,avatar)
+    shutil.copy(dir_sound+name_hash+".mp3",tool_dest+name_hash+'.mp3')
+    shutil.copy(dir_anchor+name_hash+".mp4",tool_dest+name_hash+'.mp4')
+    os.remove(dir_sound+name_hash+".mp3")
+    os.remove(dir_anchor+name_hash+".mp4")
+    notify_choozmo('sound at www.choozmo.com:8168/tools/'+name_hash+'.mp3')
+    notify_choozmo('avatar at www.choozmo.com:8168/tools/'+name_hash+'.mp4')
+
+def makeMP3(name_hash,txt,lang):
+    if lang==0:
+        tts = gTTS(txt)
+        tts.save(dir_sound+name_hash+"raw.mp3")
+    else:
+        tts = gTTS(txt,lang='zh-tw')
+        tts.save(dir_sound+name_hash+"raw.mp3")
+            #speed up 
+    ff = ffmpy.FFmpeg(inputs={dir_sound+name_hash+"raw.mp3": None}
+                            , outputs={dir_sound+name_hash+".mp3": ["-filter:a", "atempo=1.2"]})
+    ff.run()
+    os.remove(dir_sound+name_hash+"raw.mp3")
+
+
+def call_anchor(name_hash,avatar):
+    conn = rpyc.classic.connect("192.168.1.111",18812)
+    ros = conn.modules.os 
+    rsys = conn.modules.sys 
+    fr=open(dir_sound+name_hash+".mp3",'rb')# voice
+    #warning!!!    file my be replaced by other process
+    fw=conn.builtins.open('/tmp/output.mp3','wb')
+
+    while True:
+        b=fr.read(1024)
+        if b:
+            fw.write(b)
+        else:
+            break
+    fr.close()
+    fw.close()
+    val=random.randint(1000000,9999999)
+    ros.chdir('/home/jared/to_video')
+    ros.system('./p'+str(avatar)+'.sh '+str(val)+' &')
+    while True:
+        print('waiting...',val,',nh:',name_hash)
+        if ros.path.exists('/tmp/results/'+str(val)):
+            break
+        time.sleep(5)
+        
+    fr=conn.builtins.open('/tmp/results/'+str(val)+'.mp4','rb')
+    fw=open(dir_anchor+name_hash+".mp4",'wb')
+    while True:
+        b=fr.read(1024)
+        if b:
+            fw.write(b)
+        else:
+            break
+    fr.close()
+    fw.close()
+
+
+def notify_choozmo(msg):
+    #'WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD' is ChoozmoTeam
+    glist = ['WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD']
+    for gid in glist:
+        headers = {"Authorization": "Bearer " + gid,"Content-Type": "application/x-www-form-urlencoded"}
+        r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params={"message": msg})

BIN
api/util/__pycache__/models.cpython-39.pyc


BIN
api/util/__pycache__/swap_face.cpython-39.pyc


BIN
api/util/__pycache__/user.cpython-39.pyc