javascript - Discord.js record MP3 of voice channel? - Stack Overflow

I'm trying to make a record mand in my discord.js bot. My code so far is:const channel = message.

I'm trying to make a record mand in my discord.js bot. My code so far is:

const channel = message.member.voice.channel;
  if(!channel) return message.channel.send('Join a VC first!');

  const connection = await channel.join();
  const receiver = connection.receiver.createStream(message.member, {
    mode: "pcm",
    end: "silence"
  });

  const writer = receiver.pipe(fs.createWriteStream('./recording.pcm'));
  writer.on('finish', () => {
    channel.leave();
    message.channel.send('It went quiet, so I left...');
  });

That saves recording.pcm to my PC. If I try to open the file in windows media player or anything, it doesn't recognise the file type. I used Audacity import raw audio function, and I could hear my recording, so I know it works. However, giving a user that type of file is very inconvenient. How can I turn this .pcm file into a .wav or .mp3 in node.js? Thanks!

I'm trying to make a record mand in my discord.js bot. My code so far is:

const channel = message.member.voice.channel;
  if(!channel) return message.channel.send('Join a VC first!');

  const connection = await channel.join();
  const receiver = connection.receiver.createStream(message.member, {
    mode: "pcm",
    end: "silence"
  });

  const writer = receiver.pipe(fs.createWriteStream('./recording.pcm'));
  writer.on('finish', () => {
    channel.leave();
    message.channel.send('It went quiet, so I left...');
  });

That saves recording.pcm to my PC. If I try to open the file in windows media player or anything, it doesn't recognise the file type. I used Audacity import raw audio function, and I could hear my recording, so I know it works. However, giving a user that type of file is very inconvenient. How can I turn this .pcm file into a .wav or .mp3 in node.js? Thanks!

Share Improve this question asked Feb 26, 2021 at 11:46 YankueYankue 3776 silver badges15 bronze badges 2
  • 1 Why not just convert it with node-lame? It supports raw inputs in pcm format. – NullDev Commented Feb 26, 2021 at 11:52
  • node-lame's readme.md advises against use on Windows, and I am using Windows 10. – Yankue Commented Feb 26, 2021 at 14:33
Add a ment  | 

1 Answer 1

Reset to default 4

You could use ffmpeg - npm i ffmpeg

const ffmpeg = require('ffmpeg');

try {
  var process = new ffmpeg('path/to/pcm/file');
  process.then(function (audio) {
    audio.fnExtractSoundToMP3('path/to/new/file.mp3', function (error, file) {
      if (!error) console.log('Audio File: ' + file);
    });
  }, function (err) {
    console.log('Error: ' + err);      
  });
} catch (e) {
  console.log(e);
}

This should save the new mp3 file to the specified location.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745336020a4623108.html

相关推荐

  • javascript - Discord.js record MP3 of voice channel? - Stack Overflow

    I'm trying to make a record mand in my discord.js bot. My code so far is:const channel = message.

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信