本文介紹了使用不和諧機(jī)器人從用戶那里接收音頻的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在做一個不和諧的項目,在那個項目中我需要錄制用戶的聲音,我正在關(guān)注 this 文檔.
I'm working on a discord project and in that project i need to record a user voice, i'm following this document.
到目前為止,這是我寫的:
so far this is what i wrote:
const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', async message => {
if (message.content === 'a' && message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
const audio = connection.receiver.createStream('user_id?', { mode: 'pcm' });
audio.pipe(fs.createWriteStream('user_audio'));
}
});
client.login('token');
但問題是 user_audio 文件總是空的!
but the problem is that always the user_audio file is empty!
推薦答案
這是discord.js中的一個bug,要解決這個問題我們需要播放音頻...
This is a bug in discord.js, to solve this problem we need to play an audio...
const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client();
const { Readable } = require('stream');
const SILENCE_FRAME = Buffer.from([0xF8, 0xFF, 0xFE]);
class Silence extends Readable {
_read() {
this.push(SILENCE_FRAME);
this.destroy();
}
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', async message => {
if (message.content === 's' && message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
const audio = connection.receiver.createStream(message, { mode: 'pcm', end: 'manual' });
audio.pipe(fs.createWriteStream('user_audio'));
connection.play(new Silence(), { type: 'opus' });
console.log(message.member.user.id);
}
});
client.login('token');
這篇關(guān)于使用不和諧機(jī)器人從用戶那里接收音頻的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!