Working audio on bot
This commit is contained in:
@@ -2,6 +2,6 @@
|
|||||||
"TOKEN": "OTQzNzQyMDQwMjU1MTE1MzA0.Yg3eRA.ZxEbRr55xahjfaUmPY8pmS-RHTY",
|
"TOKEN": "OTQzNzQyMDQwMjU1MTE1MzA0.Yg3eRA.ZxEbRr55xahjfaUmPY8pmS-RHTY",
|
||||||
"ApplicationID": "943742040255115304",
|
"ApplicationID": "943742040255115304",
|
||||||
"GuildID": "367396189529833472",
|
"GuildID": "367396189529833472",
|
||||||
"DeviceID": "25",
|
"DeviceID": "5",
|
||||||
"DeviceName": "VoiceMeeter Aux Output (VB-Audio VoiceMeeter AUX VAIO)"
|
"DeviceName": "VoiceMeeter Aux Output (VB-Audi"
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,14 @@ export function getAudioDevice({deviceName = undefined, deviceId = undefined}){
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getAudioDevices(){
|
export function getAudioDevices(){
|
||||||
const deviceList = portAudio.getDevices();
|
const deviceList = portAudio.getDevices().map((device) => {
|
||||||
|
if (device.defaultSampleRate === 48000 || device.maxInputChannels > 0) {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).filter(Boolean);
|
||||||
console.log("Devices:", deviceList);
|
console.log("Devices:", deviceList);
|
||||||
return deviceList;
|
return deviceList;
|
||||||
}
|
}
|
||||||
@@ -26,11 +33,12 @@ export function createAudioInstance() {
|
|||||||
inOptions: {
|
inOptions: {
|
||||||
channelCount: 2,
|
channelCount: 2,
|
||||||
sampleFormat: portAudio.SampleFormat16Bit,
|
sampleFormat: portAudio.SampleFormat16Bit,
|
||||||
sampleRate: 44100,
|
sampleRate: 48000,
|
||||||
deviceId: selectedDevice.id, // Use -1 or omit the deviceId to select the default device
|
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
|
closeOnError: true, // 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
|
framesPerBuffer: 100, //(48000 / 1000) * 20, //(48000 * 16 * 2) / 1000 * 20 // (48000 * (16 / 8) * 2) / 60 / 1000 * 20 //0.025 * 48000 / 2
|
||||||
}
|
highwaterMark: 3840
|
||||||
|
},
|
||||||
});
|
});
|
||||||
//audioInstance.start();
|
//audioInstance.start();
|
||||||
return audioInstance;
|
return audioInstance;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export function join(interaction){
|
|||||||
replyToInteraction(interaction, `Ok, Joining ${voiceChannel.name}`);
|
replyToInteraction(interaction, `Ok, Joining ${voiceChannel.name}`);
|
||||||
|
|
||||||
// Declare the encoder
|
// Declare the encoder
|
||||||
const encoder = new OpusEncoder(44100, 2);
|
const encoder = new OpusEncoder(48000, 2);
|
||||||
|
|
||||||
const player = createAudioPlayer({
|
const player = createAudioPlayer({
|
||||||
behaviors: {
|
behaviors: {
|
||||||
@@ -39,13 +39,14 @@ export function join(interaction){
|
|||||||
});
|
});
|
||||||
|
|
||||||
const audioInstance = createAudioInstance();
|
const audioInstance = createAudioInstance();
|
||||||
const audioResource = createAudioResource(audioInstance, { inputType: StreamType.Raw });
|
|
||||||
|
audioInstance.on('data', buffer => {
|
||||||
|
buffer = Buffer.from(buffer);
|
||||||
|
const encoded = encoder.encode(buffer);
|
||||||
|
voiceConnection.playOpusPacket(encoded);
|
||||||
|
})
|
||||||
|
|
||||||
audioInstance.start();
|
audioInstance.start();
|
||||||
//audioInstance.on('data', buffer => {
|
|
||||||
// Do on buffer event
|
|
||||||
//})
|
|
||||||
player.play(audioResource);
|
|
||||||
voiceConnection.subscribe(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,3 +61,27 @@ export function leave(interaction){
|
|||||||
voiceConnection.destroy();
|
voiceConnection.destroy();
|
||||||
return replyToInteraction(interaction, `Goodbye`);
|
return replyToInteraction(interaction, `Goodbye`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Brute forcing the required buffer size, 16 bit, 48KHz, 2ch = 480 Bytes (need to get frames still)
|
||||||
|
let notWorking = true;
|
||||||
|
let splitIndexInverse = 0
|
||||||
|
while (notWorking) {
|
||||||
|
try {
|
||||||
|
const newBuffer = buffer.slice(buffer.length - splitIndexInverse);
|
||||||
|
console.log(timestamp ,newBuffer, "end")
|
||||||
|
const encoded = encoder.encode(newBuffer);
|
||||||
|
console.log("Working Buffer Length" ,newBuffer.length)
|
||||||
|
console.log("Working Buffer" ,newBuffer)
|
||||||
|
notWorking = false
|
||||||
|
break;
|
||||||
|
} catch (err){
|
||||||
|
console.log(err)
|
||||||
|
if (splitIndexInverse >= buffer.length) {
|
||||||
|
notWorking = false
|
||||||
|
throw new Error("Shit fucked")
|
||||||
|
}
|
||||||
|
splitIndexInverse += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user