Upload 3 files
Browse files- tts-server.py +10 -2
tts-server.py
CHANGED
|
@@ -10,8 +10,9 @@ from typing import Optional, List, Dict, Any, AsyncGenerator
|
|
| 10 |
|
| 11 |
import aiohttp
|
| 12 |
import websockets
|
| 13 |
-
from fastapi import FastAPI, HTTPException, Header, Request, BackgroundTasks
|
| 14 |
from fastapi.responses import StreamingResponse, JSONResponse
|
|
|
|
| 15 |
from pydantic import BaseModel, Field
|
| 16 |
import uvicorn
|
| 17 |
from contextlib import asynccontextmanager
|
|
@@ -32,6 +33,7 @@ PORT = 1547
|
|
| 32 |
HOST = "0.0.0.0"
|
| 33 |
MODELS_FILE = "models.json"
|
| 34 |
COOKIE_DIR = "cookie" # Directory to store cookie txt files
|
|
|
|
| 35 |
|
| 36 |
# Initialize FastAPI
|
| 37 |
@asynccontextmanager
|
|
@@ -50,6 +52,12 @@ async def lifespan(app: FastAPI):
|
|
| 50 |
yield
|
| 51 |
|
| 52 |
app = FastAPI(title="Doubao TTS OpenAI API Server", lifespan=lifespan)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# ==========================================
|
| 55 |
# Cookie Manager
|
|
@@ -337,7 +345,7 @@ async def check_speech_endpoint():
|
|
| 337 |
return {"status": "ok", "message": "Speech endpoint is ready"}
|
| 338 |
|
| 339 |
@app.post("/v1/audio/speech")
|
| 340 |
-
async def create_speech(req: OpenAIRequest):
|
| 341 |
"""
|
| 342 |
OpenAI-compatible speech generation endpoint.
|
| 343 |
"""
|
|
|
|
| 10 |
|
| 11 |
import aiohttp
|
| 12 |
import websockets
|
| 13 |
+
from fastapi import FastAPI, HTTPException, Header, Request, BackgroundTasks, Depends
|
| 14 |
from fastapi.responses import StreamingResponse, JSONResponse
|
| 15 |
+
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 16 |
from pydantic import BaseModel, Field
|
| 17 |
import uvicorn
|
| 18 |
from contextlib import asynccontextmanager
|
|
|
|
| 33 |
HOST = "0.0.0.0"
|
| 34 |
MODELS_FILE = "models.json"
|
| 35 |
COOKIE_DIR = "cookie" # Directory to store cookie txt files
|
| 36 |
+
AUTH_PASSWORD = os.getenv("PASSWORD", "sk-wei123")
|
| 37 |
|
| 38 |
# Initialize FastAPI
|
| 39 |
@asynccontextmanager
|
|
|
|
| 52 |
yield
|
| 53 |
|
| 54 |
app = FastAPI(title="Doubao TTS OpenAI API Server", lifespan=lifespan)
|
| 55 |
+
security = HTTPBearer()
|
| 56 |
+
|
| 57 |
+
async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
|
| 58 |
+
if credentials.credentials != AUTH_PASSWORD:
|
| 59 |
+
raise HTTPException(status_code=401, detail="Invalid authentication token")
|
| 60 |
+
return credentials.credentials
|
| 61 |
|
| 62 |
# ==========================================
|
| 63 |
# Cookie Manager
|
|
|
|
| 345 |
return {"status": "ok", "message": "Speech endpoint is ready"}
|
| 346 |
|
| 347 |
@app.post("/v1/audio/speech")
|
| 348 |
+
async def create_speech(req: OpenAIRequest, token: str = Depends(verify_token)):
|
| 349 |
"""
|
| 350 |
OpenAI-compatible speech generation endpoint.
|
| 351 |
"""
|