Skip to content

Commit 66f5ccd

Browse files
authored
fix: add file size validation to TTS provider test and MiniMax empty audio detection (#5999)
- Add audio data validation in MiniMax TTS get_audio() method to detect empty responses - Validate generated audio file size in TTSProvider.test() to ensure valid output - Provide detailed error messages guiding users to check group_id configuration - Auto-cleanup test audio files after validation - Fixes issue where 0KB audio files would pass TTS detection when group_id is not configured
1 parent 3379587 commit 66f5ccd

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

astrbot/core/provider/provider.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,24 @@ async def get_audio_stream(
281281
accumulated_text += text_part
282282

283283
async def test(self) -> None:
284-
await self.get_audio("hi")
284+
audio_path = await self.get_audio("hi")
285+
286+
# 检查生成的音频文件是否有效
287+
if not os.path.exists(audio_path):
288+
raise Exception("TTS test failed: audio file was not created")
289+
290+
file_size = os.path.getsize(audio_path)
291+
if file_size == 0:
292+
raise Exception(
293+
"TTS test failed: generated audio file is empty (0 bytes). "
294+
"Please check your TTS provider configuration, especially required parameters like group_id for MiniMax."
295+
)
296+
297+
# 清理测试文件
298+
try:
299+
os.remove(audio_path)
300+
except Exception:
301+
pass
285302

286303

287304
class EmbeddingProvider(AbstractProvider):

astrbot/core/provider/sources/minimax_tts_api_source.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,19 @@ async def get_audio(self, text: str) -> str:
154154
audio_stream = self._call_tts_stream(text)
155155
audio = await self._audio_play(audio_stream)
156156

157+
# 检查音频数据是否为空
158+
if not audio or len(audio) == 0:
159+
raise Exception(
160+
"MiniMax TTS API returned empty audio data. "
161+
"Please verify your configuration, especially the 'group_id' parameter. "
162+
"You can find your group_id in Account Management -> Basic Information on the MiniMax platform."
163+
)
164+
157165
# 结果保存至文件
158166
with open(path, "wb") as file:
159167
file.write(audio)
160168

161169
return path
162170

163171
except aiohttp.ClientError as e:
164-
raise e
172+
raise Exception(f"MiniMax TTS API request failed: {e!s}")

0 commit comments

Comments
 (0)