feat(TTS): refactor OhFreeMe API integration to use environment variables for configuration

pull/2558/head
MinhVu2711 4 months ago
parent de093fd1d2
commit 741f794729

@ -1,16 +1,22 @@
import base64 import base64
import json import json
import os
import random import random
import time import time
from pathlib import Path from pathlib import Path
import requests import requests
from dotenv import load_dotenv
from utils import settings from utils import settings
from utils.console import print_substep from utils.console import print_substep
API_URL = "https://tts.ohfree.me/api/tts" # Load environment variables from .env file
# JWT token for authentication (replace if needed) load_dotenv()
OHFREEME_API_URL = os.getenv("OHFREEME_API_URL", "")
OHFREEME_BASE_URL = os.getenv("OHFREEME_BASE_URL", "")
JWT_TOKEN = os.getenv("OHFREEME_JWT_TOKEN", "")
VOICES_FILE = Path(__file__).resolve().parent.parent / "config" / "ohfreeme_voices.json" VOICES_FILE = Path(__file__).resolve().parent.parent / "config" / "ohfreeme_voices.json"
MAX_RETRIES = 3 MAX_RETRIES = 3
RATE_LIMIT_WAIT = 10 RATE_LIMIT_WAIT = 10
@ -98,15 +104,15 @@ class OhFreeMe:
"accept": "*/*", "accept": "*/*",
"cache-control": "no-cache", "cache-control": "no-cache",
"content-type": "application/json", "content-type": "application/json",
"origin": "https://tts.ohfree.me", "origin": OHFREEME_BASE_URL,
"cookie": f"auth_token={JWT_TOKEN}", "cookie": f"auth_token={JWT_TOKEN}",
"referer": "https://tts.ohfree.me/", "referer": OHFREEME_BASE_URL,
"user-agent": self._pick_user_agent(), "user-agent": self._pick_user_agent(),
} }
# streaming NDJSON response with debug logging # streaming NDJSON response with debug logging
for attempt in range(MAX_RETRIES): for attempt in range(MAX_RETRIES):
resp = requests.post(API_URL, json=payload, headers=headers, stream=True) resp = requests.post(OHFREEME_API_URL, json=payload, headers=headers, stream=True)
# Ratelimit handling first line may contain error object # Ratelimit handling first line may contain error object
try: try:
first_line = next(resp.iter_lines()) first_line = next(resp.iter_lines())

@ -19,3 +19,4 @@ transformers==4.52.4
ffmpeg-python==0.2.0 ffmpeg-python==0.2.0
elevenlabs==1.57.0 elevenlabs==1.57.0
yt-dlp==2025.10.22 yt-dlp==2025.10.22
python-dotenv==1.0.0

Loading…
Cancel
Save