Spaces:
Sleeping
Sleeping
fix
Browse files
app.py
CHANGED
@@ -618,9 +618,9 @@ def lang_detector(text):
|
|
618 |
except Exception as e:
|
619 |
return f"ERROR:{str(e)}"
|
620 |
|
621 |
-
def trim_text(text,language):
|
622 |
-
limit_cj = 120
|
623 |
-
limit_en = 60
|
624 |
search_limit_cj = limit_cj+30
|
625 |
search_limit_en = limit_en +30
|
626 |
text = text.replace('\n', '').strip()
|
|
|
618 |
except Exception as e:
|
619 |
return f"ERROR:{str(e)}"
|
620 |
|
621 |
+
def trim_text(text,language):
|
622 |
+
limit_cj = 120
|
623 |
+
limit_en = 60
|
624 |
search_limit_cj = limit_cj+30
|
625 |
search_limit_en = limit_en +30
|
626 |
text = text.replace('\n', '').strip()
|
main.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from fastapi import FastAPI, Body, File, Form, UploadFile, Response
|
2 |
from fastapi.responses import FileResponse
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
-
from model import clone_voice
|
5 |
import os
|
6 |
from enum import Enum
|
7 |
import uvicorn
|
@@ -25,15 +25,16 @@ class DefaultVoice(str, Enum):
|
|
25 |
@app.post("/tts")
|
26 |
async def tts(
|
27 |
custom_voice_file: UploadFile = File(None, description="用户自定义声音"),
|
28 |
-
language: Language = Form(..., description="语言选择"),
|
29 |
voice: DefaultVoice = Form(None),
|
30 |
-
text: str = Form(..., description="转换文本")
|
31 |
-
)
|
32 |
if custom_voice_file is not None:
|
33 |
os.makedirs("static/tmp", exist_ok=True)
|
34 |
content = await file.read()
|
35 |
filename = f"static/tmp/{file.filename}"
|
36 |
with open(filename, "wb") as f:
|
|
|
|
|
37 |
f.write(content)
|
38 |
voice = filename
|
39 |
wav_path = clone_voice(
|
|
|
1 |
from fastapi import FastAPI, Body, File, Form, UploadFile, Response
|
2 |
from fastapi.responses import FileResponse
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
+
from model import clone_voice,lang_detector
|
5 |
import os
|
6 |
from enum import Enum
|
7 |
import uvicorn
|
|
|
25 |
@app.post("/tts")
|
26 |
async def tts(
|
27 |
custom_voice_file: UploadFile = File(None, description="用户自定义声音"),
|
|
|
28 |
voice: DefaultVoice = Form(None),
|
29 |
+
text: str = Form(..., description="转换文本")):
|
30 |
+
language = lang_detector(text)
|
31 |
if custom_voice_file is not None:
|
32 |
os.makedirs("static/tmp", exist_ok=True)
|
33 |
content = await file.read()
|
34 |
filename = f"static/tmp/{file.filename}"
|
35 |
with open(filename, "wb") as f:
|
36 |
+
|
37 |
+
|
38 |
f.write(content)
|
39 |
voice = filename
|
40 |
wav_path = clone_voice(
|
model.py
CHANGED
@@ -30,6 +30,9 @@ logging.getLogger("multipart").setLevel(logging.WARNING)
|
|
30 |
# from download import *
|
31 |
# download()
|
32 |
|
|
|
|
|
|
|
33 |
if "_CUDA_VISIBLE_DEVICES" in os.environ:
|
34 |
os.environ["CUDA_VISIBLE_DEVICES"] = os.environ["_CUDA_VISIBLE_DEVICES"]
|
35 |
tz = pytz.timezone('Asia/Singapore')
|
@@ -619,8 +622,7 @@ def lang_detector(text):
|
|
619 |
return f"ERROR:{str(e)}"
|
620 |
|
621 |
def trim_text(text,language):
|
622 |
-
|
623 |
-
limit_en = 60 #words
|
624 |
search_limit_cj = limit_cj+30
|
625 |
search_limit_en = limit_en +30
|
626 |
text = text.replace('\n', '').strip()
|
|
|
30 |
# from download import *
|
31 |
# download()
|
32 |
|
33 |
+
limit_cj = int(os.environ.get("limit_cj", 120)) #character
|
34 |
+
limit_en = int(os.environ.get("limit_en", 60)) #words
|
35 |
+
|
36 |
if "_CUDA_VISIBLE_DEVICES" in os.environ:
|
37 |
os.environ["CUDA_VISIBLE_DEVICES"] = os.environ["_CUDA_VISIBLE_DEVICES"]
|
38 |
tz = pytz.timezone('Asia/Singapore')
|
|
|
622 |
return f"ERROR:{str(e)}"
|
623 |
|
624 |
def trim_text(text,language):
|
625 |
+
|
|
|
626 |
search_limit_cj = limit_cj+30
|
627 |
search_limit_en = limit_en +30
|
628 |
text = text.replace('\n', '').strip()
|