Improve alsa usage

- added command handler to check devices
This commit is contained in:
Logan Cusano
2023-03-26 02:20:17 -04:00
parent a8be6598f2
commit 9a2416e2ff
2 changed files with 26 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
import { getDeviceID } from '../utilities/configHandler.js';
// Modules
import alsaInstance from 'alsa-capture';
import executeAsyncConsoleCommand from "../utilities/executeConsoleCommand.js";
import { returnAlsaDeviceObject } from "../utilities/executeConsoleCommands.js";
// Debug
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
// Global Vars
@@ -30,8 +30,10 @@ export async function confirmAudioDevice({deviceName = undefined, deviceId = und
*/
export async function getAudioDevices(){
// Exec output contains both stderr and stdout outputs
const deviceList = await executeAsyncConsoleCommand("arecord -L");
const deviceList = await returnAlsaDeviceObject();
log.DEBUG("Device list: ", deviceList);
return deviceList;
}
/**
@@ -48,7 +50,7 @@ export async function createAudioInstance() {
channels: 2,
format: "S16_BE",
rate: 48000,
device: selectedDevice.id ?? "default", // Use -1 or omit the deviceId to select the default device
device: selectedDevice.name ?? "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

View File

@@ -25,4 +25,25 @@ export default async function executeAsyncConsoleCommand(consoleCommand) {
// TODO add some error checking
return output;
}
export async function returnAlsaDeviceObject() {
const listAlsaDevicesCommand = "arecord -L";
const commandResponse = await executeAsyncConsoleCommand(listAlsaDevicesCommand);
const brokenCommand = String(commandResponse).split('\n');
var devices = [];
var i = 0;
for (const responseLine of brokenCommand) {
if (!String(responseLine).match(/^\s/g)) {
const tempDevice = {
id: i,
name: responseLine
}
devices.push(tempDevice);
i += 1;
}
}
return devices;
}