Switching to direct encoding (RPi4)

This commit is contained in:
Logan Cusano
2023-03-30 23:19:38 -04:00
parent 999affce93
commit 6f98e59b26
3 changed files with 6 additions and 4 deletions

View File

@@ -3,13 +3,14 @@ const { DebugBuilder } = require("../utilities/debugBuilder.js");
const log = new DebugBuilder("client-bot", "commandController");
// Modules
const { joinVoiceChannel, VoiceConnectionStatus, getVoiceConnection } = require("@discordjs/voice");
const { OpusEncoder } = require("@discordjs/opus");
//const { OpusEncoder } = require("@discordjs/opus");
// Utilities
const {replyToInteraction} = require("../utilities/messageHandler.js");
const {createAudioInstance} = require("../controllers/audioController.js");
const { encode } = require("../utilities/arm64-linux.node");
// Declare the encoder
const encoder = new OpusEncoder(48000, 2);
//const encoder = new OpusEncoder(48000, 2);
/**
* Join the specified voice channel
@@ -42,8 +43,9 @@ exports.join = async function join({interaction= undefined, guildID= undefined,
const audioInstance = await createAudioInstance();
audioInstance.on('audio', (buffer) => {
buffer = Buffer.from(buffer);
log.DEBUG("Audio buffer: ", buffer);
const encoded = encoder.encode(buffer);
const encoded = encode(buffer);
log.DEBUG("Encoded packet: ", encoded);
// TODO Add a function here to check the volume of either buffer and only play audio to discord when there is audio to be played
voiceConnection.playOpusPacket(encoded);