feat: add script tts backend

This commit is contained in:
2026-05-17 16:36:06 +08:00
parent 1016111d19
commit 6b426c2b68
21 changed files with 808 additions and 5 deletions
+19
View File
@@ -0,0 +1,19 @@
# Emotion Museum TTS Service
Install on `101.200.208.45`:
```bash
cd /data/programs/emotion-museum/tts-service
python3 -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
cd /data/programs/emotion-museum/tts-service
uvicorn app:app --host 127.0.0.1 --port 19110
curl http://127.0.0.1:19110/health
```
+59
View File
@@ -0,0 +1,59 @@
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()
class SynthesizeRequest(BaseModel):
text: str = Field(min_length=1, max_length=5000)
voice: str = "default_zh_female"
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"}
@app.post("/synthesize")
def synthesize(request: SynthesizeRequest):
output = Path(request.outputPath)
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)
except Exception as exc:
return {
"success": False,
"audioPath": None,
"durationMs": None,
"engine": "melotts",
"errorMessage": str(exc),
}
return {
"success": True,
"audioPath": str(output),
"durationMs": None,
"engine": "melotts",
}
@@ -0,0 +1,13 @@
[Unit]
Description=Emotion Museum TTS Service
After=network.target
[Service]
Type=simple
WorkingDirectory=/data/programs/emotion-museum/tts-service
ExecStart=/data/programs/emotion-museum/tts-service/.venv/bin/uvicorn app:app --host 127.0.0.1 --port 19110
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,3 @@
fastapi==0.111.0
uvicorn[standard]==0.30.1
pydantic==2.7.4