mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 05:13:59 +08:00
update: 更改to_tts保存临时文件判断
This commit is contained in:
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user