prism-media
prism-media copied to clipboard
[BUG] TypeError: failed to downcast any to number
Issue: When recording the audio of a user, it causes an error (discord.js)
Steps to reproduce:
Install nodejs, use Discord, initiate your discord bot, use theses packages:
"dependencies": {
"@discordjs/opus": "^0.6.0",
"@discordjs/voice": "^0.6.0",
"axios": "^0.21.3",
"bufferutil": "^4.0.3",
"colors": "^1.4.0",
"crypto": "^1.0.1",
"discord.js": "^13.1.0",
"ffmpeg-static": "^4.4.0",
"fs": "^0.0.1-security",
"libsodium-wrappers": "^0.7.9",
"moment": "^2.29.1",
"ms": "^2.1.3",
"node-crc": "^2.0.11",
"nodemon": "^2.0.12",
"prism-media": "^2.0.0-alpha.0",
"stream": "^0.0.2",
"utf-8-validate": "^5.0.5",
"youtube-dl-exec": "^1.2.5",
"ytdl-core": "^4.9.1"
}
Use this code to initiate a connection betwwen the bot and the user, and so to record his voice :
//if user send message ".record" then, join voice channel and send info to prism-media to record and export to .ogg file
console.log("Got a record call")
console.log(message.guildId)
if (message.guildId) {
console.log("This server doesn't have any subscription [voice registered]")
/**
* @type {DiscordVoice.VoiceConnection}
*/
var connection;
if (!connection) {
if (message.member instanceof Discord.GuildMember && message.member.voice.channel) {
const channel = message.member.voice.channel;
connection = await util.voiceconnectToChannel(channel);
} else {
await message.channel.send('Join a voice channel and then try that again!');
return;
}
}
try {
await DiscordVoice.entersState(connection, DiscordVoice.VoiceConnectionStatus.Ready, 20_000);
const receiver = connection.receiver;
receiver.speaking.on('start', (userId) => {
console.log(receiver)
console.log(userId)
console.log(client.users.cache.get(userId))
util.createListeningStream(receiver, userId, client.users.cache.get(userId));
});
} catch (error) {
console.warn(error);
await message.channel.send('Failed to join voice channel within 20 seconds, please try again later!');
}
}
const oggStream = new opus.OggLogicalBitstream(
{
opusHead: new opus.OpusHead({
channelCount: 2,
sampleRate: 48000,
}),
pageSizeControl: {
maxPackets: 10,
},
}
);
I'm using the exact same code here : https://github.com/discordjs/voice/blob/main/examples/recorder/src/createListeningStream.ts
but using it in javascript, installed typescript to have compatibility working, returning me this error when speaking:
Further details:
- Operating System: Linux Debian 10 x86_64
- Node.js version: 16.6.0
- Commit I'm using: "prism-media": "^2.0.0-alpha.0",
I don't know if it's because i'm tired, or if i didn't set something, if you have any idea, tell me, will re-check tomorrow :)
Okay so i have finally found a FIX !! Here is the code to fix this strange error :
const oggStream = new opus.OggLogicalBitstream(
{
opusHead: new opus.OpusHead({
channelCount: 2,
sampleRate: 48000,
}),
pageSizeControl: {
maxPackets: 10,
},
crc: false
}
);
crc: false
This basically disables crc