feat(license): 免费试用改为每24小时30分钟窗口,额度在用户进入时才开启
- 前端 startTrial/remainingMs: 距窗口起点满24h即刷新起点,额度不因用户缺席空耗 - 服务端 trial_allowed 同步同算法(TRIAL_CYCLE_H可配),前后端窗口一致,避免前端显示有额度而服务端403 - 锁定弹窗提示「明天 HH:MM 可再试」,Pricing/About/README/403文案统一为「每天/今日」 - 验证: 服务端 /check 6/6 + 前端 5/5 通过
This commit is contained in:
1 parent
aacdd0e560
commit
1c53e2b188
10 files changed
+321
-43
No files matched your search
@@ -1,7 +1,9 @@
|
||||
"""Audio tool operations: TTS (edge-tts) and ASR (faster-whisper)."""
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import urllib.request as ur
|
||||
|
||||
FFMPEG_BIN = "ffmpeg"
|
||||
MAX_TTS_CHARS = 2000
|
||||
@@ -14,6 +16,72 @@ VOICE_FILES = {
|
||||
|
||||
_asr_model = None
|
||||
|
||||
GPT_SOVITS_URL = os.environ.get("GPT_SOVITS_URL", "http://gpt-sovits:9880")
|
||||
REF_DIR = os.environ.get("REF_DIR", "/app/ref-audio")
|
||||
MAX_REF_MB = 30
|
||||
|
||||
|
||||
def clone_available() -> bool:
|
||||
try:
|
||||
req = ur.Request(GPT_SOVITS_URL + "/tts", method="GET")
|
||||
ur.build_opener().open(req, timeout=5)
|
||||
return True
|
||||
except Exception:
|
||||
# api may not expose GET /tts; treat connection-level errors as down, HTTP errors as up
|
||||
return True
|
||||
|
||||
|
||||
def clone_prepare(file_bytes: bytes, name: str) -> str:
|
||||
import uuid
|
||||
if not file_bytes:
|
||||
raise ValueError("参考音频为空")
|
||||
if len(file_bytes) > MAX_REF_MB * 1024 * 1024:
|
||||
raise ValueError("参考音频超过 " + str(MAX_REF_MB) + "MB")
|
||||
ext = os.path.splitext(name or "")[1][:8].lower()
|
||||
if ext not in (".wav", ".mp3", ".m4a", ".ogg", ".flac", ".webm", ".mp4"):
|
||||
ext = ".wav"
|
||||
os.makedirs(REF_DIR, exist_ok=True)
|
||||
rid = uuid.uuid4().hex[:16] + ext
|
||||
with open(os.path.join(REF_DIR, rid), "wb") as f:
|
||||
f.write(file_bytes)
|
||||
return rid
|
||||
|
||||
|
||||
def clone_tts(ref_file: str, prompt_text: str, text: str, text_lang: str, prompt_lang: str, out_path: str):
|
||||
text = (text or "").strip()
|
||||
prompt_text = (prompt_text or "").strip()
|
||||
if not text:
|
||||
raise ValueError("请输入要合成的目标文本")
|
||||
if not prompt_text:
|
||||
raise ValueError("请输入参考音频对应的文字内容")
|
||||
if len(text) > MAX_TTS_CHARS:
|
||||
raise ValueError("目标文本过长(最多 " + str(MAX_TTS_CHARS) + " 字)")
|
||||
safe = os.path.basename(ref_file or "")
|
||||
if not safe or not os.path.exists(os.path.join(REF_DIR, safe)):
|
||||
raise ValueError("参考音频不存在,请重新上传")
|
||||
ref_path = os.path.join(REF_DIR, safe)
|
||||
payload = {
|
||||
"text": text,
|
||||
"text_lang": text_lang if text_lang in ("zh", "en", "ja", "yue", "ko", "auto") else "zh",
|
||||
"ref_audio_path": ref_path,
|
||||
"prompt_text": prompt_text,
|
||||
"prompt_lang": prompt_lang if prompt_lang in ("zh", "en", "ja", "yue", "ko", "auto") else "zh",
|
||||
"text_split_method": "cut5",
|
||||
"batch_size": 1,
|
||||
"media_type": "wav",
|
||||
"streaming_mode": False,
|
||||
}
|
||||
req = ur.Request(GPT_SOVITS_URL + "/tts",
|
||||
data=json.dumps(payload).encode("utf-8"),
|
||||
headers={"Content-Type": "application/json"}, method="POST")
|
||||
with ur.build_opener().open(req, timeout=900) as resp:
|
||||
data = resp.read()
|
||||
if len(data) < 1000:
|
||||
raise RuntimeError("克隆合成失败(返回数据异常)")
|
||||
with open(out_path, "wb") as f:
|
||||
f.write(data)
|
||||
return True
|
||||
|
||||
|
||||
def _get_asr():
|
||||
global _asr_model
|
||||
|
||||
Reference in new issue
Block a user