Files
ai-video-fullstack/backend/config.py
Xin Wang e857828fe5 Add WebRTC TURN configuration and related enhancements
- Introduce a new `.env.example` file for environment variable setup, including `PUBLIC_IP`, `TURN_SECRET`, and `TURN_URLS` for WebRTC TURN server configuration.
- Update `docker-compose.yaml` to support TURN server deployment with necessary environment variables and commands.
- Enhance backend configuration and routes to include WebRTC ICE server settings, allowing for STUN/TURN server integration.
- Implement a new service for managing WebRTC ICE server configurations, providing credentials for TURN when configured.
- Modify frontend API to fetch ICE server configurations dynamically, improving support for cross-network voice preview.
2026-07-06 17:45:53 +08:00

56 lines
2.0 KiB
Python

"""集中读取环境变量。所有模型接口的环境变量兜底都在这里。"""
import os
from dotenv import load_dotenv
load_dotenv()
def _split(value: str) -> list[str]:
return [item.strip() for item in value.split(",") if item.strip()]
# ---- LLM(DeepSeek 等,OpenAI 兼容) ----
LLM_BASE_URL = os.getenv("LLM_BASE_URL", "https://api.deepseek.com/v1")
LLM_API_KEY = os.getenv("LLM_API_KEY", "")
LLM_MODEL = os.getenv("LLM_MODEL", "deepseek-chat")
# ---- STT(SenseVoice / FunASR,OpenAI 兼容) ----
STT_BASE_URL = os.getenv("STT_BASE_URL", "http://localhost:8001/v1")
STT_API_KEY = os.getenv("STT_API_KEY", "local")
STT_MODEL = os.getenv("STT_MODEL", "sensevoice")
# ---- TTS(CosyVoice,OpenAI 兼容) ----
TTS_BASE_URL = os.getenv("TTS_BASE_URL", "http://localhost:8002/v1")
TTS_API_KEY = os.getenv("TTS_API_KEY", "local")
TTS_MODEL = os.getenv("TTS_MODEL", "cosyvoice")
TTS_VOICE = os.getenv("TTS_VOICE", "中文女")
# ---- Realtime(可选) ----
REALTIME_API_KEY = os.getenv("REALTIME_API_KEY", "")
REALTIME_MODEL = os.getenv("REALTIME_MODEL", "gpt-realtime")
# ---- 数据库(Postgres) ----
DATABASE_URL = os.getenv(
"DATABASE_URL",
"postgresql+asyncpg://postgres:postgres@localhost:5432/postgres",
)
# ---- 服务 ----
HOST = os.getenv("HOST", "0.0.0.0")
PORT = int(os.getenv("PORT", "8000"))
CORS_ORIGINS = _split(
os.getenv("CORS_ORIGINS", "http://localhost:3000,http://127.0.0.1:3000")
)
# ---- WebRTC TURN(公网跨网语音预览;本地开发留空即可) ----
# TURN_URLS 示例:turn:182.92.86.220:3478?transport=udp,turn:182.92.86.220:3478?transport=tcp
TURN_URLS = _split(os.getenv("TURN_URLS", ""))
# coturn --use-auth-secret 时与 --static-auth-secret 一致;后端据此签发短时凭证
TURN_SECRET = os.getenv("TURN_SECRET", "")
# 不用 secret 时可改静态账号(需 coturn --user=...)
TURN_USERNAME = os.getenv("TURN_USERNAME", "")
TURN_PASSWORD = os.getenv("TURN_PASSWORD", "")
TURN_CREDENTIAL_TTL = int(os.getenv("TURN_CREDENTIAL_TTL", "86400"))