tomoya 1 周之前
父節點
當前提交
7df64b32a4
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      backend/app/app/api/api_v1/endpoints/text2zip.py

+ 14 - 0
backend/app/app/api/api_v1/endpoints/text2zip.py

@@ -47,6 +47,18 @@ LINE_TOKEN = 'o8dqdVL2k8aiWO4jy3pawZamBu53bbjoSh2u0GJ7F0j'
 
 router = APIRouter()
 
+def select_voice(lang:str, gender:str='Female'):
+    if "-" in lang:
+        local = lang
+        lang = lang.split("-")[0]
+    voices = asyncio.run(VoicesManager.create())
+    if local:
+        voice = voices.find(Gender=gender, Language=lang, Locale=local)
+    else:
+        voice = voices.find(Gender=gender, Language=lang)
+    
+    return voice
+
 def gen_prompt(content:str):
     client = OpenAI(base_url="http://192.168.192.84:8080/v1", api_key='choozmo9')
 
@@ -182,6 +194,7 @@ async def wait_finish(model, email, texts, lang):
     ws['A1'] = '大標'
     ws['B1'] = '字幕'
     ws['C1'] = '素材'
+    ws['D1'] = '聲音'
     td = Path(f'/tmp/{datetime.datetime.now().strftime("%Y%m%d%H%M%S-td")}')
     td.mkdir(exist_ok=False)
     dir = td/f'{datetime.datetime.now().strftime("%Y%m%d%H%M%S")}'
@@ -200,6 +213,7 @@ async def wait_finish(model, email, texts, lang):
         print("after", str(img_path))
         ws['B'+ str(i+2)] = re.sub(punctuation, r"\\", text)
         ws['C'+ str(i+2)] = img_path.name
+    ws['D2'] = select_voice(lang)
     excel_path = Path(dir/'script.xlsx')
     wb.save(excel_path)
     output_dir = '/tmp'