feat: 小程序脚本首页重构 + 社交数据导入 + TTS 播放优化

- 后端:新增社交数据导入/审批/洞察生成 API(SocialContent/SocialInsight)
- 后端:优化脚本上下文服务,TTS 服务增强
- 小程序:重构脚本首页布局,新增社交导入页面
- 小程序:新增 useTtsPlayer composable,移除旧 ScriptAudioPlayer 组件
- 小程序:新增社交导入服务,优化请求服务
- SQL:新增社交数据导入建表脚本
- 文档:补充设计文档和实施计划

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-20 07:18:02 +08:00
parent 83cc32999b
commit ee5a6aba5d
50 changed files with 5723 additions and 1246 deletions
+6 -5
View File
@@ -4,14 +4,15 @@ Install on `101.200.208.45`:
```bash
cd /data/programs/emotion-museum/tts-service
python3 -m venv .venv
python3.11 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
git clone https://github.com/myshell-ai/MeloTTS.git /data/programs/MeloTTS
cd /data/programs/MeloTTS
/data/programs/emotion-museum/tts-service/.venv/bin/pip install -e .
/data/programs/emotion-museum/tts-service/.venv/bin/python -m unidic download
mkdir -p models
curl -L -o models/zh_CN-huayan-medium.onnx \
https://hf-mirror.com/rhasspy/piper-voices/resolve/v1.0.0/zh/zh_CN/huayan/medium/zh_CN-huayan-medium.onnx
curl -L -o models/zh_CN-huayan-medium.onnx.json \
https://hf-mirror.com/rhasspy/piper-voices/resolve/v1.0.0/zh/zh_CN/huayan/medium/zh_CN-huayan-medium.onnx.json
cd /data/programs/emotion-museum/tts-service
uvicorn app:app --host 127.0.0.1 --port 19110
+35 -21
View File
@@ -1,14 +1,15 @@
import subprocess
from pathlib import Path
from threading import Lock
from fastapi import FastAPI
from pydantic import BaseModel, Field
app = FastAPI(title="Emotion Museum TTS")
_model = None
_speaker_ids = None
_model_lock = Lock()
BASE_DIR = Path(__file__).resolve().parent
PIPER_BIN = BASE_DIR / ".venv" / "bin" / "piper"
PIPER_MODEL = BASE_DIR / "models" / "zh_CN-huayan-medium.onnx"
PIPER_CONFIG = BASE_DIR / "models" / "zh_CN-huayan-medium.onnx.json"
class SynthesizeRequest(BaseModel):
@@ -17,20 +18,13 @@ class SynthesizeRequest(BaseModel):
outputPath: str
def get_model():
global _model, _speaker_ids
with _model_lock:
if _model is None:
from melo.api import TTS
_model = TTS(language="ZH", device="cpu")
_speaker_ids = _model.hps.data.spk2id
return _model, _speaker_ids
@app.get("/health")
def health():
return {"status": "ok"}
return {
"status": "ok",
"engine": "piper",
"modelReady": PIPER_MODEL.exists() and PIPER_CONFIG.exists(),
}
@app.post("/synthesize")
@@ -39,15 +33,35 @@ def synthesize(request: SynthesizeRequest):
output.parent.mkdir(parents=True, exist_ok=True)
try:
model, speaker_ids = get_model()
speaker_id = speaker_ids.get("ZH")
model.tts_to_file(request.text, speaker_id, str(output), speed=1.0)
if not PIPER_BIN.exists():
raise RuntimeError(f"piper binary not found: {PIPER_BIN}")
if not PIPER_MODEL.exists() or not PIPER_CONFIG.exists():
raise RuntimeError("piper Chinese voice model is not installed")
subprocess.run(
[
str(PIPER_BIN),
"--model",
str(PIPER_MODEL),
"--config",
str(PIPER_CONFIG),
"--output_file",
str(output),
"--sentence-silence",
"0.35",
],
input=request.text,
text=True,
check=True,
capture_output=True,
timeout=180,
)
except Exception as exc:
return {
"success": False,
"audioPath": None,
"durationMs": None,
"engine": "melotts",
"engine": "piper",
"errorMessage": str(exc),
}
@@ -55,5 +69,5 @@ def synthesize(request: SynthesizeRequest):
"success": True,
"audioPath": str(output),
"durationMs": None,
"engine": "melotts",
"engine": "piper",
}
@@ -1,3 +1,4 @@
fastapi==0.111.0
uvicorn[standard]==0.30.1
pydantic==2.7.4
piper-tts==1.4.2