Upload 2 files
Browse files- requirements.txt +2 -1
- tts-server.py +11 -1
requirements.txt
CHANGED
|
@@ -3,4 +3,5 @@ uvicorn
|
|
| 3 |
aiohttp
|
| 4 |
websockets==10.4
|
| 5 |
pydantic
|
| 6 |
-
aiofiles
|
|
|
|
|
|
| 3 |
aiohttp
|
| 4 |
websockets==10.4
|
| 5 |
pydantic
|
| 6 |
+
aiofiles
|
| 7 |
+
python-dotenv
|
tts-server.py
CHANGED
|
@@ -17,6 +17,10 @@ from fastapi.responses import StreamingResponse, JSONResponse
|
|
| 17 |
from pydantic import BaseModel, Field
|
| 18 |
import uvicorn
|
| 19 |
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# ==========================================
|
| 22 |
# Configuration & Setup
|
|
@@ -35,6 +39,7 @@ HOST = "0.0.0.0"
|
|
| 35 |
MODELS_FILE = "models.json"
|
| 36 |
COOKIE_DIR = "cookie" # Directory to store cookie txt files
|
| 37 |
AUDIO_DIR = "saved_audio"
|
|
|
|
| 38 |
|
| 39 |
# Initialize FastAPI
|
| 40 |
@asynccontextmanager
|
|
@@ -408,11 +413,16 @@ async def stream_speech_get(
|
|
| 408 |
voice: str,
|
| 409 |
speed: float = 1.0,
|
| 410 |
pitch: float = 0.0,
|
| 411 |
-
response_format: str = "aac"
|
|
|
|
| 412 |
):
|
| 413 |
"""
|
| 414 |
GET endpoint for direct streaming (e.g. for <audio src="...">).
|
| 415 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
if not input:
|
| 417 |
raise HTTPException(status_code=400, detail="Input text is required")
|
| 418 |
|
|
|
|
| 17 |
from pydantic import BaseModel, Field
|
| 18 |
import uvicorn
|
| 19 |
from contextlib import asynccontextmanager
|
| 20 |
+
from dotenv import load_dotenv
|
| 21 |
+
|
| 22 |
+
# Load environment variables
|
| 23 |
+
load_dotenv()
|
| 24 |
|
| 25 |
# ==========================================
|
| 26 |
# Configuration & Setup
|
|
|
|
| 39 |
MODELS_FILE = "models.json"
|
| 40 |
COOKIE_DIR = "cookie" # Directory to store cookie txt files
|
| 41 |
AUDIO_DIR = "saved_audio"
|
| 42 |
+
AUTH_PASSWORD = os.getenv("PASSWORD", "sk-wei123")
|
| 43 |
|
| 44 |
# Initialize FastAPI
|
| 45 |
@asynccontextmanager
|
|
|
|
| 413 |
voice: str,
|
| 414 |
speed: float = 1.0,
|
| 415 |
pitch: float = 0.0,
|
| 416 |
+
response_format: str = "aac",
|
| 417 |
+
token: Optional[str] = None
|
| 418 |
):
|
| 419 |
"""
|
| 420 |
GET endpoint for direct streaming (e.g. for <audio src="...">).
|
| 421 |
"""
|
| 422 |
+
# Verify token if password is set
|
| 423 |
+
if AUTH_PASSWORD and token != AUTH_PASSWORD:
|
| 424 |
+
raise HTTPException(status_code=401, detail="Invalid authentication token")
|
| 425 |
+
|
| 426 |
if not input:
|
| 427 |
raise HTTPException(status_code=400, detail="Input text is required")
|
| 428 |
|