Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a2416e2ff | ||
|
|
a8be6598f2 |
@@ -39,7 +39,7 @@ export default async function join({interaction= undefined, guildID= undefined,
|
|||||||
selfDeaf: false,
|
selfDeaf: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const audioInstance = createAudioInstance();
|
const audioInstance = await createAudioInstance();
|
||||||
|
|
||||||
audioInstance.on('data', buffer => {
|
audioInstance.on('data', buffer => {
|
||||||
buffer = Buffer.from(buffer);
|
buffer = Buffer.from(buffer);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { getDeviceID } from '../utilities/configHandler.js';
|
import { getDeviceID } from '../utilities/configHandler.js';
|
||||||
// Modules
|
// Modules
|
||||||
import alsaInstance from 'alsa-capture';
|
import alsaInstance from 'alsa-capture';
|
||||||
import executeAsyncConsoleCommand from "../utilities/executeConsoleCommand.js";
|
import { returnAlsaDeviceObject } from "../utilities/executeConsoleCommands.js";
|
||||||
// Debug
|
// Debug
|
||||||
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
|
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
|
||||||
// Global Vars
|
// Global Vars
|
||||||
@@ -16,8 +16,8 @@ const log = new ModuleDebugBuilder("bot", "audioController");
|
|||||||
* @param deviceId The ID of the device being queried
|
* @param deviceId The ID of the device being queried
|
||||||
* @returns {unknown}
|
* @returns {unknown}
|
||||||
*/
|
*/
|
||||||
export function confirmAudioDevice({deviceName = undefined, deviceId = undefined}){
|
export async function confirmAudioDevice({deviceName = undefined, deviceId = undefined}){
|
||||||
const deviceList = 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);
|
if (deviceId) return deviceList.find(device => device.id === deviceId);
|
||||||
if (deviceName) return deviceList.find(device => device.name === deviceName);
|
if (deviceName) return deviceList.find(device => device.name === deviceName);
|
||||||
@@ -28,10 +28,12 @@ export function confirmAudioDevice({deviceName = undefined, deviceId = undefined
|
|||||||
*
|
*
|
||||||
* @returns {unknown[]}
|
* @returns {unknown[]}
|
||||||
*/
|
*/
|
||||||
export function getAudioDevices(){
|
export async function getAudioDevices(){
|
||||||
// Exec output contains both stderr and stdout outputs
|
// Exec output contains both stderr and stdout outputs
|
||||||
const deviceList = executeAsyncConsoleCommand("arecord -L");
|
const deviceList = await returnAlsaDeviceObject();
|
||||||
log.DEBUG("Device list: ", deviceList);
|
log.DEBUG("Device list: ", deviceList);
|
||||||
|
|
||||||
|
return deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,15 +42,15 @@ export function getAudioDevices(){
|
|||||||
*
|
*
|
||||||
* @returns new portAudio.AudioIO
|
* @returns new portAudio.AudioIO
|
||||||
*/
|
*/
|
||||||
export function createAudioInstance() {
|
export async function createAudioInstance() {
|
||||||
const selectedDevice = 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 alsaInstance({
|
return new alsaInstance({
|
||||||
channels: 2,
|
channels: 2,
|
||||||
format: "S16_BE",
|
format: "S16_BE",
|
||||||
rate: 48000,
|
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
|
periodSize: 100, //(48000 / 1000) * 20, //(48000 * 16 * 2) / 1000 * 20 // (48000 * (16 / 8) * 2) / 60 / 1000 * 20 //0.025 * 48000 / 2
|
||||||
periodTime: undefined,
|
periodTime: undefined,
|
||||||
// highwaterMark: 3840
|
// highwaterMark: 3840
|
||||||
|
|||||||
+21
@@ -25,4 +25,25 @@ export default async function executeAsyncConsoleCommand(consoleCommand) {
|
|||||||
|
|
||||||
// TODO add some error checking
|
// TODO add some error checking
|
||||||
return output;
|
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;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user