update: 更改to_tts保存临时文件判断

This commit is contained in:
Sakura-RanChen
2025-06-04 16:46:49 +08:00
parent 3657f6ce75
commit 23cb7616d9
17 changed files with 253 additions and 92 deletions
@@ -17,7 +17,8 @@ class TTSProvider(TTSProviderBase):
self.voice = config.get("private_voice")
else:
self.voice = config.get("voice", "alloy")
self.response_format = "wav"
self.response_format = config.get("format", "wav")
self.audio_file_type = config.get("format", "wav")
# 处理空字符串的情况
speed = config.get("speed", "1.0")
@@ -40,8 +41,11 @@ class TTSProvider(TTSProviderBase):
}
response = requests.post(self.api_url, json=data, headers=headers)
if response.status_code == 200:
with open(output_file, "wb") as audio_file:
audio_file.write(response.content)
if output_file:
with open(output_file, "wb") as audio_file:
audio_file.write(response.content)
else:
return response.content
else:
raise Exception(
f"OpenAI TTS请求失败: {response.status_code} - {response.text}"