fix: Fish Audio走东京VPS反向代理,解决国内服务器无法直连问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lanhao
2026-07-02 23:58:52 +08:00
parent 433903365c
commit effcceb44b
+10 -3
View File
@@ -2,6 +2,11 @@ import os
import requests import requests
PROXY_URL = 'http://202.182.125.133:8443/fish-api/v1/tts'
PROXY_USER = 'fishproxy'
PROXY_PASS = 'AO7C6SiovkRydkSHsUPJaOZw0CBh9mp0'
def synthesize_fish_audio(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral'): def synthesize_fish_audio(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral'):
api_key = os.getenv('FISH_AUDIO_API_KEY', '') api_key = os.getenv('FISH_AUDIO_API_KEY', '')
if not api_key: if not api_key:
@@ -20,9 +25,8 @@ def synthesize_fish_audio(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral
if tag: if tag:
text = f"{tag}{text}" text = f"{tag}{text}"
url = 'https://api.fish.audio/v1/tts'
headers = { headers = {
'Authorization': f'Bearer {api_key}', 'X-Fish-Auth': f'Bearer {api_key}',
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
@@ -34,7 +38,10 @@ def synthesize_fish_audio(text, speed=1.0, pitch=0, volume=1.0, emotion='neutral
'volume': max(-20, min(20, (volume - 1.0) * 20)), 'volume': max(-20, min(20, (volume - 1.0) * 20)),
} }
response = requests.post(url, json=payload, headers=headers, timeout=60, stream=True) response = requests.post(
PROXY_URL, json=payload, headers=headers,
auth=(PROXY_USER, PROXY_PASS), timeout=120
)
if response.status_code != 200: if response.status_code != 200:
raise Exception(f'Fish Audio API错误: {response.status_code} - {response.text[:200]}') raise Exception(f'Fish Audio API错误: {response.status_code} - {response.text[:200]}')