Skip to content

[fix] 将Minimax TTS默认输出格式改为wav以解决RIFF错误#7797

Merged
Soulter merged 1 commit intoAstrBotDevs:masterfrom
enemywind-zm:fix/minimax-tts-wav-format
Apr 26, 2026
Merged

[fix] 将Minimax TTS默认输出格式改为wav以解决RIFF错误#7797
Soulter merged 1 commit intoAstrBotDevs:masterfrom
enemywind-zm:fix/minimax-tts-wav-format

Conversation

@enemywind-zm
Copy link
Copy Markdown
Contributor

@enemywind-zm enemywind-zm commented Apr 25, 2026

问题

在 QQ 官方平台插件中,处理来自 Minimax TTS 的语音时,会抛出错误:处理语音时出错: file does not start with RIFF id

原因

Minimax TTS 提供商 (minimax_tts_api_source.py) 默认配置的音频输出格式为 mp3,而 qqofficial_message_event.py 中的 wav_to_tencent_silk 函数要求输入为 WAV 格式(具有 RIFF 文件头)。

解决方案

minimax_tts_api_source.py 文件中 ProviderMiniMaxTTSAPI 类的 audio_setting 字典的 format 键值,从 "mp3" 修改为 "wav"

结果

修改后,Minimax TTS 生成的音频文件将直接为 WAV 格式,从而被下游函数正确识别和处理,修复上述错误。

相关 Issue

修复 issue #7144, issue #7795

Modifications / 改动点

  • 修改文件: minimax_tts_api_source.py
  • 具体修改: 第 57 行,将 "format": "mp3" 改为 "format": "wav"
  • 影响范围: 仅影响使用 Minimax TTS 服务生成的音频格式
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

[2026-04-25 12:29:05.097] [Core] [INFO] [result_decorate.stage:301]: TTS 结果: /home/astrbot/AstrBot/data/temp/minimax_tts_api_31e97f25-bf49-45cb-a9ae-4fbcac7e93d1.wav
[2026-04-25 12:29:05.098] [Core] [INFO] [respond.stage:183]: Prepare to send - /DD74A1EA717091E5085E2CF5606E1FFC: [ComponentType.Record]
result


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Bug Fixes:

  • Fix Minimax TTS output format mismatch that caused RIFF-related errors in QQ official platform integration.

## 问题
在 QQ 官方平台插件中,处理来自 Minimax TTS 的语音时,会抛出错误:`处理语音时出错: file does not start with RIFF id`。
## 原因
Minimax TTS 提供商 (`minimax_tts_api_source.py`) 默认配置的音频输出格式为 `mp3`,而 `qqofficial_message_event.py` 中的 `wav_to_tencent_silk` 函数要求输入为 WAV 格式(具有 RIFF 文件头)。
## 解决方案
将 `minimax_tts_api_source.py` 文件中 `ProviderMiniMaxTTSAPI` 类的 `audio_setting` 字典的 `format` 键值,从 `"mp3"` 修改为 `"wav"`。
## 结果
修改后,Minimax TTS 生成的音频文件将直接为 WAV 格式,从而被下游函数正确识别和处理,修复上述错误。
Copilot AI review requested due to automatic review settings April 25, 2026 12:54
@auto-assign auto-assign Bot requested review from Fridemn and anka-afk April 25, 2026 12:54
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 25, 2026
@dosubot dosubot Bot added the area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. label Apr 25, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Consider making the Minimax TTS output format configurable (e.g., via settings or constructor arguments) instead of hardcoding wav, so other integrations that still expect mp3 can opt in or out without code changes.
  • Now that the audio format is wav, double-check that any places relying on file extensions or MIME types (e.g., upload APIs or response headers) use this value from a single source of truth rather than assuming mp3 elsewhere.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making the Minimax TTS output format configurable (e.g., via settings or constructor arguments) instead of hardcoding `wav`, so other integrations that still expect `mp3` can opt in or out without code changes.
- Now that the audio format is `wav`, double-check that any places relying on file extensions or MIME types (e.g., upload APIs or response headers) use this value from a single source of truth rather than assuming `mp3` elsewhere.

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/sources/minimax_tts_api_source.py" line_range="148-150" />
<code_context>
         temp_dir = get_astrbot_temp_path()
         os.makedirs(temp_dir, exist_ok=True)
-        path = os.path.join(temp_dir, f"minimax_tts_api_{uuid.uuid4()}.mp3")
+        path = os.path.join(temp_dir, f"minimax_tts_api_{uuid.uuid4()}.wav")

         try:
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Derive the file extension from `audio_setting["format"]` to avoid future mismatches.

The container format is currently defined both in `audio_setting["format"]` and in the hardcoded `.wav` suffix. If they ever diverge, files will be mislabelled. Building the filename from `self.audio_setting["format"]` (e.g. `f"minimax_tts_api_{uuid.uuid4()}.{self.audio_setting['format']}"`) keeps them consistent and avoids this risk.

```suggestion
        temp_dir = get_astrbot_temp_path()
        os.makedirs(temp_dir, exist_ok=True)
        path = os.path.join(
            temp_dir,
            f"minimax_tts_api_{uuid.uuid4()}.{self.audio_setting['format']}",
        )
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 148 to +150
temp_dir = get_astrbot_temp_path()
os.makedirs(temp_dir, exist_ok=True)
path = os.path.join(temp_dir, f"minimax_tts_api_{uuid.uuid4()}.mp3")
path = os.path.join(temp_dir, f"minimax_tts_api_{uuid.uuid4()}.wav")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Derive the file extension from audio_setting["format"] to avoid future mismatches.

The container format is currently defined both in audio_setting["format"] and in the hardcoded .wav suffix. If they ever diverge, files will be mislabelled. Building the filename from self.audio_setting["format"] (e.g. f"minimax_tts_api_{uuid.uuid4()}.{self.audio_setting['format']}") keeps them consistent and avoids this risk.

Suggested change
temp_dir = get_astrbot_temp_path()
os.makedirs(temp_dir, exist_ok=True)
path = os.path.join(temp_dir, f"minimax_tts_api_{uuid.uuid4()}.mp3")
path = os.path.join(temp_dir, f"minimax_tts_api_{uuid.uuid4()}.wav")
temp_dir = get_astrbot_temp_path()
os.makedirs(temp_dir, exist_ok=True)
path = os.path.join(
temp_dir,
f"minimax_tts_api_{uuid.uuid4()}.{self.audio_setting['format']}",
)

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the audio output format from mp3 to wav in the MiniMax TTS API source. The reviewer suggests removing the bitrate parameter from the audio settings because it is only applicable to the mp3 format according to the API documentation.

Comment on lines 65 to 69
self.audio_setting: dict = {
"sample_rate": 32000,
"bitrate": 128000,
"format": "mp3",
"format": "wav",
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

由于输出格式已更改为 wav,建议从 audio_setting 中移除 bitrate 参数。根据 MiniMax T2A V2 API 文档,bitrate 参数仅在格式为 mp3 时有效。在请求 wav 格式时发送此参数可能会被 API 忽略或视为冗余。移除它可以使配置更加清晰且符合 API 规范。

        self.audio_setting: dict = {
            "sample_rate": 32000,
            "format": "wav",
        }

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 修复 MiniMax TTS 在 QQ 官方平台语音处理链路中因音频格式不匹配导致的 file does not start with RIFF id 错误,使 MiniMax TTS 的默认输出与下游 WAV 处理逻辑一致。

Changes:

  • 将 MiniMax TTS API 请求的默认 audio_setting.formatmp3 调整为 wav
  • 将临时输出文件扩展名从 .mp3 改为 .wav,与实际生成格式保持一致

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 26, 2026
@Soulter Soulter merged commit 3c1d0cd into AstrBotDevs:master Apr 26, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants