Revert to Naudiodon and Update Config
- Changed to .env file
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
// Config
|
||||
const { getDeviceID } = require('../utilities/configHandler.js');
|
||||
// Modules
|
||||
const alsaInstance = require('alsa-capture');
|
||||
const portAudio = require('naudiodon');
|
||||
const { returnAlsaDeviceObject } = require("../utilities/executeConsoleCommands.js");
|
||||
// Debug
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
// 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)
|
||||
@@ -19,8 +19,13 @@ const log = new DebugBuilder("client-bot", "audioController");
|
||||
async function confirmAudioDevice({deviceName = undefined, deviceId = undefined}){
|
||||
const deviceList = await getAudioDevices();
|
||||
if (!deviceName && !deviceId) throw new Error("No device given");
|
||||
if (deviceId) return deviceList.find(device => device.id === deviceId);
|
||||
if (deviceName) return deviceList.find(device => device.name === deviceName);
|
||||
let confirmedDevice;
|
||||
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;
|
||||
|
||||
@@ -31,9 +36,16 @@ exports.confirmAudioDevice = confirmAudioDevice;
|
||||
*/
|
||||
async function getAudioDevices(){
|
||||
// Exec output contains both stderr and stdout outputs
|
||||
const deviceList = await returnAlsaDeviceObject();
|
||||
log.DEBUG("Device list: ", deviceList);
|
||||
|
||||
//const deviceList = await returnAlsaDeviceObject();
|
||||
const deviceList = portAudio.getDevices().map((device) => {
|
||||
if (device.maxInputChannels > 2) {
|
||||
return device;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}).filter(Boolean);
|
||||
log.VERBOSE("Device List: ", deviceList);
|
||||
return deviceList;
|
||||
}
|
||||
exports.getAudioDevices = getAudioDevices;
|
||||
@@ -48,6 +60,19 @@ async function createAudioInstance() {
|
||||
const selectedDevice = await confirmAudioDevice({deviceId: getDeviceID()});//{deviceName: "VoiceMeeter VAIO3 Output (VB-Au"});
|
||||
log.DEBUG("Device selected from config: ", selectedDevice);
|
||||
// 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({
|
||||
channels: 2,
|
||||
format: "U8",
|
||||
@@ -57,5 +82,7 @@ async function createAudioInstance() {
|
||||
periodTime: undefined,
|
||||
// highwaterMark: 3840
|
||||
});
|
||||
*/
|
||||
|
||||
}
|
||||
exports.createAudioInstance = createAudioInstance;
|
||||
Reference in New Issue
Block a user