You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node-RED Join节点合并TTS生成的Buffer时顺序错乱及格式不符问题求助

Node-RED Join节点合并TTS生成的Buffer时顺序错乱及格式不符问题求助

各位Node-RED的大佬们好,我现在正在做一个用OpenAI TTS API实现文本转语音的流程,目前卡在Join节点上了,怎么都没法按预期合并生成的音频Buffer,想请教下大家有没有解决办法。

我的流程大致是这样的:先用Split节点拆分文本,拆分后的消息序列都带有msg.parts属性;接着把每个消息里的文本通过API转成MP3格式的Buffer;最后想把这些Buffer按顺序合并成完整的音频,但Join节点就是不给力,遇到两个问题:

  • 用「自动」模式时,合并后的结果根本不是Buffer,而是把各个payload当成字符串拼接起来了,完全不对
  • 改成「手动」模式,设置返回Buffer类型后,Join节点又完全忽略了msg.parts.index的顺序,合并出来的音频顺序是乱的,应该是按消息到达顺序拼的,不是拆分时的原始顺序

我之前试过在Join节点前加一个Sort节点,想先按msg.parts.index排序,但没成功,估计是我配置错了。另外确认过,经过HTTP请求节点之后,消息里的msg.parts信息是保留着的,没有丢失。

最后附上我用来拆分文本的节点代码,方便大家排查问题:

let maxChunkSize = 4096;

let text = msg.payload;

let chunks = [];

let startIndex = 0;

while (startIndex < text.length) {

let endIndex = Math.min(startIndex + maxChunkSize, text.length);

// Ensure we end on a full word by searching for the last space within the limit
if (endIndex < text.length) {

while (text[endIndex] !== ' ' && endIndex > startIndex) {

endIndex--;

}

}

// If no space was found, just split at the maxChunkSize
if (endIndex === startIndex) {

endIndex = Math.min(startIndex + maxChunkSize, text.length);

}

chunks.push(text.substring(startIndex, endIndex).trim());

startIndex = endIndex;

}

msg.payload = chunks;

return msg; // Return as an array of messages to be compatible with the Split node.

备注:内容来源于stack exchange,提问作者Steve

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 13:10:31