Initial update to ALSA
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
// Config
|
||||
import {getDeviceID} from '../utilities/configHandler.js'
|
||||
import {getDeviceID} from '../utilities/configHandler.js';
|
||||
// Modules
|
||||
import portAudio from 'naudiodon';
|
||||
import alsaInstance from 'alsa-capture';
|
||||
import executeConsoleCommand from "../utilities/executeConsoleCommand.js";
|
||||
// Debug
|
||||
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
|
||||
// Global Vars
|
||||
const log = new ModuleDebugBuilder("bot", "audioController");
|
||||
|
||||
/**
|
||||
@@ -27,16 +29,9 @@ export function confirmAudioDevice({deviceName = undefined, deviceId = undefined
|
||||
* @returns {unknown[]}
|
||||
*/
|
||||
export function getAudioDevices(){
|
||||
const deviceList = portAudio.getDevices().map((device) => {
|
||||
if (device.defaultSampleRate === 48000 || device.maxInputChannels > 0) {
|
||||
return device;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}).filter(Boolean);
|
||||
//log.DEBUG("Device List: ", deviceList);
|
||||
return deviceList;
|
||||
// Exec output contains both stderr and stdout outputs
|
||||
const deviceList = executeConsoleCommand("arecord -L");
|
||||
log.DEBUG("Device list: ", deviceList);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,15 +44,13 @@ export function createAudioInstance() {
|
||||
const selectedDevice = 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: 100, //(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: "S16_BE",
|
||||
rate: 48000,
|
||||
device: selectedDevice.id ?? "default", // Use -1 or 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
|
||||
periodTime: undefined,
|
||||
// highwaterMark: 3840
|
||||
});
|
||||
}
|
||||
@@ -17,9 +17,9 @@
|
||||
"@mapbox/node-pre-gyp": "^1.0.10",
|
||||
"debug": "^4.3.4",
|
||||
"discord.js": "^14.7.1",
|
||||
"naudiodon": "^2.3.6",
|
||||
"node-gyp": "^9.3.0",
|
||||
"libsodium-wrappers": "^0.7.10"
|
||||
"libsodium-wrappers": "^0.7.10",
|
||||
"alsa-capture": "0.3.0"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
22
Client/discord-bot/utilities/executeConsoleCommand.js
Normal file
22
Client/discord-bot/utilities/executeConsoleCommand.js
Normal file
@@ -0,0 +1,22 @@
|
||||
// Modules
|
||||
import { promisify } from 'util';
|
||||
// Debug
|
||||
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
|
||||
// Global Vars
|
||||
const log = new ModuleDebugBuilder("bot", "executeConsoleCommand");
|
||||
const exec = promisify(require('child_process').exec);
|
||||
|
||||
|
||||
exports.executeAsyncConsoleCommand = (consoleCommand) => {
|
||||
// Check to see if the command is a real command
|
||||
// TODO needs to be improved
|
||||
const acceptableCommands = [ "arecord -L" ];
|
||||
if (!acceptableCommands.includes(consoleCommand)) {
|
||||
log.WARN("Console command is not acceptable: ", consoleCommand);
|
||||
return undefined;
|
||||
}
|
||||
const tempOutput = exec();
|
||||
|
||||
// TODO add some error checking
|
||||
return tempOutput.stdout.trim();
|
||||
}
|
||||
Reference in New Issue
Block a user