diff --git a/Client/controllers/audioController.js b/Client/controllers/audioController.js index 403ab4f..feae85d 100644 --- a/Client/controllers/audioController.js +++ b/Client/controllers/audioController.js @@ -50,7 +50,7 @@ async function createAudioInstance() { // Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream return new alsaInstance({ channels: 2, - format: "S16_BE", + format: "U8", rate: 48000, device: selectedDevice.name ?? "default", // Omit the deviceId to select the default device periodSize: 100, //(48000 / 1000) * 20, //(48000 * 16 * 2) / 1000 * 20 // (48000 * (16 / 8) * 2) / 60 / 1000 * 20 //0.025 * 48000 / 2 diff --git a/Client/controllers/commandController.js b/Client/controllers/commandController.js index e94524f..f826c28 100644 --- a/Client/controllers/commandController.js +++ b/Client/controllers/commandController.js @@ -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); diff --git a/Client/utilities/arm64-linux.node b/Client/utilities/arm64-linux.node new file mode 100644 index 0000000..f2c6ba4 Binary files /dev/null and b/Client/utilities/arm64-linux.node differ