Revert to Naudiodon and Update Config

- Changed to .env file
This commit is contained in:
Logan Cusano
2023-04-30 03:52:20 -04:00
parent b248e7f40e
commit 95c99971a2
7 changed files with 2601 additions and 49 deletions

View File

@@ -1 +1,8 @@
DEBUG="client:*"; DEBUG="client:*"
TOKEN=""
# Bot Config
APPLICATION_ID=""
GUILD_ID=""
# Audio Config
AUDIO_DEVICE_ID="1"
AUDIO_DEVICE_NAME="VoiceMeeter VAIO3 Output (VB-Au"

View File

@@ -1,6 +0,0 @@
{
"ApplicationID": "943742040255115304",
"GuildID": "367396189529833472",
"DeviceID": "1",
"DeviceName": "VoiceMeeter VAIO3 Output (VB-Au"
}

View File

@@ -1,12 +1,12 @@
// Config // Config
const { getDeviceID } = require('../utilities/configHandler.js'); const { getDeviceID } = require('../utilities/configHandler.js');
// Modules // Modules
const alsaInstance = require('alsa-capture'); const portAudio = require('naudiodon');
const { returnAlsaDeviceObject } = require("../utilities/executeConsoleCommands.js"); const { returnAlsaDeviceObject } = require("../utilities/executeConsoleCommands.js");
// Debug // Debug
const { DebugBuilder } = require("../utilities/debugBuilder.js"); const { DebugBuilder } = require("../utilities/debugBuilder.js");
// Global Vars // Global Vars
const log = new DebugBuilder("client-bot", "audioController"); const log = new DebugBuilder("client", "audioController");
/** /**
* Checks to make sure the selected audio device is available and returns the device object (PortAudio Device Info) * Checks to make sure the selected audio device is available and returns the device object (PortAudio Device Info)
@@ -19,8 +19,13 @@ const log = new DebugBuilder("client-bot", "audioController");
async function confirmAudioDevice({deviceName = undefined, deviceId = undefined}){ async function confirmAudioDevice({deviceName = undefined, deviceId = undefined}){
const deviceList = await getAudioDevices(); const deviceList = await getAudioDevices();
if (!deviceName && !deviceId) throw new Error("No device given"); if (!deviceName && !deviceId) throw new Error("No device given");
if (deviceId) return deviceList.find(device => device.id === deviceId); let confirmedDevice;
if (deviceName) return deviceList.find(device => device.name === deviceName); if (deviceId) confirmedDevice = deviceList.find(device => device.id === deviceId);
if (deviceName) confirmedDevice = deviceList.find(device => device.name === deviceName);
log.DEBUG("Confirmed Audio Device: ", confirmedDevice);
return confirmedDevice;
} }
exports.confirmAudioDevice = confirmAudioDevice; exports.confirmAudioDevice = confirmAudioDevice;
@@ -31,9 +36,16 @@ exports.confirmAudioDevice = confirmAudioDevice;
*/ */
async function getAudioDevices(){ async function getAudioDevices(){
// Exec output contains both stderr and stdout outputs // Exec output contains both stderr and stdout outputs
const deviceList = await returnAlsaDeviceObject(); //const deviceList = await returnAlsaDeviceObject();
log.DEBUG("Device list: ", deviceList); const deviceList = portAudio.getDevices().map((device) => {
if (device.maxInputChannels > 2) {
return device;
}
else {
return null;
}
}).filter(Boolean);
log.VERBOSE("Device List: ", deviceList);
return deviceList; return deviceList;
} }
exports.getAudioDevices = getAudioDevices; exports.getAudioDevices = getAudioDevices;
@@ -48,6 +60,19 @@ async function createAudioInstance() {
const selectedDevice = await confirmAudioDevice({deviceId: getDeviceID()});//{deviceName: "VoiceMeeter VAIO3 Output (VB-Au"}); const selectedDevice = await confirmAudioDevice({deviceId: getDeviceID()});//{deviceName: "VoiceMeeter VAIO3 Output (VB-Au"});
log.DEBUG("Device selected from config: ", selectedDevice); log.DEBUG("Device selected from config: ", selectedDevice);
// Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream // Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream
return new portAudio.AudioIO({
inOptions: {
channelCount: 2,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 48000,
deviceId: selectedDevice.id, // Use -1 or omit the deviceId to select the default device
closeOnError: true, // Close the stream if an audio error is detected, if set false then just log the error
framesPerBuffer: 20, //(48000 / 1000) * 20, //(48000 * 16 * 2) / 1000 * 20 // (48000 * (16 / 8) * 2) / 60 / 1000 * 20 //0.025 * 48000 / 2
highwaterMark: 3840,
},
});
/*
return new alsaInstance({ return new alsaInstance({
channels: 2, channels: 2,
format: "U8", format: "U8",
@@ -57,5 +82,7 @@ async function createAudioInstance() {
periodTime: undefined, periodTime: undefined,
// highwaterMark: 3840 // highwaterMark: 3840
}); });
*/
} }
exports.createAudioInstance = createAudioInstance; exports.createAudioInstance = createAudioInstance;

2533
Client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,11 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"main": "app.js", "main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"preinstall": "echo preinstall",
"postinstall": "echo postinstall"
},
"dependencies": { "dependencies": {
"convert-units": "^2.3.4", "convert-units": "^2.3.4",
"cookie-parser": "~1.4.4", "cookie-parser": "~1.4.4",
@@ -21,6 +26,6 @@
"discord.js": "^14.7.1", "discord.js": "^14.7.1",
"node-gyp": "^9.3.0", "node-gyp": "^9.3.0",
"libsodium-wrappers": "^0.7.10", "libsodium-wrappers": "^0.7.10",
"alsa-capture": "0.3.0" "naudiodon": "^2.3.6"
} }
} }

View File

@@ -1,10 +1,26 @@
#!/bin/bash #!/bin/bash
# Check if the user is root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# Check for updates
apt-get update
# Install Node Repo
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
# Update the system
apt-get update apt-get update
apt-get upgrade -y apt-get upgrade -y
# Install the necessary packages
apt-get install -y nodejs npm libopus-dev gcc make alsa-utils libasound2 libasound2-dev libpulse-dev pulseaudio apulse apt-get install -y nodejs npm libopus-dev gcc make alsa-utils libasound2 libasound2-dev libpulse-dev pulseaudio apulse
# Ensure pulse audio is running
pulseaudio pulseaudio
# Install the node packages from the project
npm i npm i

View File

@@ -4,45 +4,33 @@ const log = new DebugBuilder("client", "configController");
// Modules // Modules
const { readFileSync } = require('fs'); const { readFileSync } = require('fs');
const path = require("path"); const path = require("path");
require('dotenv').config();
function getConfig() { const GuildID = process.env.GUILD_ID;
const botConfigObj = JSON.parse(readFileSync(path.resolve("./config/botConfig.json"))) const ApplicationID = process.env.APPLICATION_ID;
return botConfigObj; const DeviceID = parseInt(process.env.AUDIO_DEVICE_ID);
} const DeviceName = process.env.AUDIO_DEVICE_NAME;
exports.getConfig = getConfig;
function getGuildID() { function getGuildID() {
const parsedJSON = getConfig(); log.DEBUG("Guild ID: ", GuildID);
const guildID = parsedJSON.GuildID; return GuildID;
log.DEBUG("Guild ID: ", guildID);
return guildID;
} }
exports.getGuildID = getGuildID; exports.getGuildID = getGuildID;
function getApplicationID() { function getApplicationID() {
const parsedJSON = getConfig(); log.DEBUG("Application ID: ", ApplicationID);
const appID = parsedJSON.ApplicationID; return ApplicationID;
log.DEBUG("Application ID: ", appID);
return appID;
} }
exports.getApplicationID = getApplicationID; exports.getApplicationID = getApplicationID;
function getDeviceID(){ function getDeviceID(){
const parsedJSON = getConfig(); log.DEBUG("Device ID: ", DeviceID);
const deviceID = parseInt(parsedJSON.DeviceID); return DeviceID;
log.DEBUG("Device ID: ", deviceID);
return deviceID;
} }
exports.getDeviceID = getDeviceID; exports.getDeviceID = getDeviceID;
function getDeviceName(){ function getDeviceName(){
const parsedJSON = getConfig(); log.DEBUG("Device Name: ", DeviceName);
const deviceName = parsedJSON.DeviceName; return DeviceName;
log.DEBUG("Device Name: ", deviceName);
return deviceName;
} }
exports.getDeviceName = getDeviceID; exports.getDeviceName = getDeviceID;