Parcourir la source

add avatar tool

ming il y a 3 ans
Parent
commit
ad5c0199d3
1 fichiers modifiés avec 19 ajouts et 1 suppressions
  1. 19 1
      api/routers/toolAvatarVoiceOnly.py

+ 19 - 1
api/routers/toolAvatarVoiceOnly.py

@@ -2,7 +2,6 @@ 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
@@ -27,6 +26,24 @@ dir_sound = ''
 dir_anchor = ''
 tool_dest = '/var/www/html/tools/'
 
+
+@app.post("/genAvatar_uploadmp3/")
+async def genAvatar_uploadmp3(file: UploadFile = File(...)):
+    name_hash = str(time.time()).replace('.','')
+
+    with open(dir_sound+name_hash+".mp3", "wb+") as file_object:
+        file_object.write(file.file.read())
+    
+    
+    x = threading.Thread(target=makeAvatar, args=(name_hash))
+    x.start()
+    return {'msg':'ok'}
+
+def makeAvatar(name_hash):
+    call_anchor(name_hash,17)
+    notify_choozmo('avatar at www.choozmo.com:8168/tools/'+name_hash+'.mp4')
+    os.remove(dir_sound+name_hash+".mp3")
+
 @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))
@@ -35,6 +52,7 @@ async def get_material(text_in: text_in):
 
 def memberOfQueue(txt,lang,avatar):
     q.put(compose(txt,lang,avatar))
+    
 
 def compose(txt,lang,avatar):
     name_hash = str(time.time()).replace('.','')