A
A
anubis4652020-09-05 17:00:56
Node.js
anubis465, 2020-09-05 17:00:56

How to implement a recording of a conversation in the discord through your bot?

They recently suggested that I add the function of recording a voice channel, I started, but then I realized that I did not know how to implement the recording itself.

client.on('message', async message => {
    if(message.content == `${prefix}join`) {
  if (message.member.voice.channel) {
        const connection = await message.member.voice.channel.join();
        message.channel.bulkDelete(1)
        message.channel.send(`${message.author} ку, я тебя слушаю!`)
  }}
});

client.on('message', async message => {
    if(message.content == `${prefix}leave`) {
  if (message.member.voice.channel) {
        const connection = await message.member.voice.channel.leave();
        message.channel.bulkDelete(1)
        message.channel.send(`${message.author}, ну ладно, я пошёл(`)
  }}
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-09-06
@anubis465

1) connect the native module of the node (fs) file system: 2) create a readable s16le PCM audio stream:
const fs = require('fs');

const audio = await connection.receiver.createStream(user, { mode: 'pcm' });

3) write a line to create files with sounds from the voice channel:
audio.pipe(fs.createWriteStream('audio')); 
/*
в папке с вашим ботом будут появляться закодированные файлы, со звуком
типа "PCM" и с названием "audio".
*/

note: files are not saved in .mp3 / .mp4 type formats, they are saved as an encoded set of characters - the so-called "raw data", which can be manually listened to using the Audacity software :
listening to files in Audacity

File > Import > Raw Data, после чего, выбираете закодированный файл.
в качестве кодировки (encoding), выбираете Signed 16-bit PCM; в качестве порядка файлов (byte order) - Little-endian.
далее, 2 стерео-канала (2 Channels (Stereo)) и частоту дискретизации (sample rate) - 48000 Гц (Hz).

D
Dinesh_Chugtai, 2020-09-05
@Dinesh_Chugtai

Check out this library, audio receiving is implemented here
https://discordjs.guide/voice/receiving-audio.html...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question