// Config import { getDeviceID, getDeviceName } from '../utilities/configHandler.js' // Modules import portAudio from 'naudiodon'; import {createAudioResource} from "@discordjs/voice"; export function getAudioDevice({deviceName = undefined, deviceId = undefined}){ const deviceList = getAudioDevices(); if (!deviceName && !deviceId) throw new Error("No device given"); if (deviceName) return deviceList.find(device => device.name === deviceName); if (deviceId) return deviceList.find(device => device.id === deviceId); } export function getAudioDevices(){ const deviceList = portAudio.getDevices(); console.log("Devices:", deviceList); return deviceList; } export function createAudioInstance() { //const resource = createAudioResource(); const selectedDevice = getAudioDevice({deviceId: getDeviceID()});//{deviceName: "VoiceMeeter VAIO3 Output (VB-Au"}); console.log(selectedDevice); // Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream const audioInstance = new portAudio.AudioIO({ inOptions: { channelCount: 2, sampleFormat: portAudio.SampleFormat16Bit, sampleRate: 44100, deviceId: selectedDevice.id, // Use -1 or omit the deviceId to select the default device closeOnError: false, // Close the stream if an audio error is detected, if set false then just log the error framesPerBuffer: 0 // 44100 / 1000 * 120 / 2 // Get 120ms of audio } }); //audioInstance.start(); return audioInstance; }