From 8c561c5ec2b94b6b35a3a2ff9a282d70a9cef659 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Fri, 1 May 2026 10:59:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20MiniMax=20TTS=20API=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=AF=B4=E6=98=8E=E5=8F=8A=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d9a9ba2 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# MiniMax Text-to-Speech API 踩坑记录 + +## 问题 + +调用 MiniMax TTS API 时,返回的音频数据无法正常播放。 + +## 原因 + +MiniMax TTS API 返回的音频数据采用 **hex(十六进制)编码**,而不是常见的 base64 编码。 + +API 响应结构: +```json +{ + "data": { + "audio": "4944330400000000086a54..." + } +} +``` + +`49443304` 是 `ID3` 的十六进制表示,这是 MP3 文件头的标识。如果误用 base64 解码,会得到乱码,导致音频文件无法播放。 + +## 解决 + +将 hex 字符串转换为 Buffer: + +```typescript +const audioBuffer = Buffer.from(audioHex, "hex"); +``` + +## 修复后的代码 + +```typescript +const audioHex = result.data.audio || result.data.audio_file!; +const audioBuffer = Buffer.from(audioHex, "hex"); +``` + +## 其他注意事项 + +1. **成功响应没有 `code` 字段**:API 请求成功时不返回 `code` 字段,只有失败时才返回。因此检查逻辑应为 `if (result.code && result.code !== 0)` +2. **环境变量**:需要设置 `MINIMAX_API_KEY`