最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何叠加两个音频文件 Node JS ffmpeg

网站源码admin42浏览0评论

如何叠加两个音频文件 Node JS ffmpeg

如何叠加两个音频文件 Node JS ffmpeg

我的代码只正确工作一次,只有在我重新启动程序后才开始正常工作。第一次代码输出正确的音频,一个叠加在另一个之上,第二次只有一个持续时间为15 秒。我正在尝试获取两个音频文件来帮助 Node.js 使用 FFMPEG。你有什么想法如何解决它?我的代码如下所示。

async songMerge(bg_id, text) {
    const bgMusic = await this.airtable
      .table("BackgroundMusic")
      .select({ view: "View", filterByFormula: `ID = '${bg_id}'` })
      .firstPage();
    if (!bgMusic.length) throw new Error("is not found");

    const result = await fetch(
      ``,
      {
        method: "POST",
        headers: {
          accept: "audio/mpeg",
          "xi-api-key": "token",
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          text,
          voice_settings: {
            stability: 0,
            similarity_boost: 0,
          },
        }),
      }
    );

    const audioBuffer = await result.arrayBuffer();
    const filePath = path.join(__dirname, "../../../", "audio.mp3");
    await fs.writeFileSync(filePath, Buffer.from(audioBuffer));

    const test = await fetch(`${bgMusic[0].fields.AudioLink}`);
    const audioBufferr = await test.arrayBuffer();
    const filePathh = path.join(__dirname, "../../../", "test.mp3");
    await fs.writeFileSync(filePathh, Buffer.from(audioBufferr));

    await mergeAudio(filePathh, filePath);
  }
回答如下:
发布评论

评论列表(0)

  1. 暂无评论