#i have an arraybuffer how can i trasform it to use in createAudioResource()?
71 messages · Page 1 of 1 (latest)
- What are your intents?
GuildVoiceStatesis required to receive voice data! - Show what dependencies you are using --
generateDependencyReport()is exported from@discordjs/voice. - Try looking at common examples: https://github.com/discordjs/voice-examples.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
and after that i can push it in the method?
do u have the example code ? i never worked on audio so im very dumb at that
yes
no
is it possible to play the audio instantaneously, like a normal user, I enclose the code from which I have to take the buffers
if(isValidBuffer(ev.frame.data.buffer)){
logger('Adding audio', 'info');
const resource = createAudioResource(bufferToReadable(ev.frame.data.buffer), { inlineVolume: true });
resource.volume.setVolume(1.0);
player.play(resource);
}
});
what are you working with? what is frame
im thinking its better to just create a Readable and push your buffer into it and play the readable outside of this loop
im trying to do something like voice call
with an ia
but what is ev.frame
@tacit shard what package/website/whatever are you getting the data from
from another api
which is?
🫠
okay nevermind, just do this
i thought to do an intervall
no
what i said is the best option
because the way you have it now (and with interval) you are re-creating a different stream every time you receive an audio buffer
it is bad
i want make an intervall out of the event , because i have to create the readable again if i want do it automatically
but u only need to do make the readable once if you keep pushing the buffer data to it
or are you telling me that by writing it out, the readable is automatically updated once created and also plays the new buffers?
if you push yes thats how streams work
tysm i'll test it
if(isValidBuffer(ev.frame.data.buffer)){
logger('Adding audio', 'info');
readable.push(ev.frame.data.buffer);
}
});
player.play(createAudioResource(readable))```
is this what you mean?
@marble folio
try
it saves the data but if i play i can't play it if its null
since it runs it once and the readable is empty at that time it will not play the audio
put infinity as option for silence frames
what do u mean?
when the stream fully consumes the buffer you gave it, the stream will be empty (and end), not playing audio is correct
so you need to put silence frame inbetween
in createAudioResource theres an option
name?
CreateAudioResourceOptions @0.17.0
Options that are set when creating a new audio resource.
const readable = new Readable({
read(){}
});
const player = createAudioPlayer();
connection.subscribe(player);
callCharacter.output.on("frameReceived", ev => {
readable.push(Buffer.from(ev.frame.data.buffer));
readable.push(null);
});
const resource = createAudioResource(readable, {silencePaddingFrames: 5});
player.play(resource);```
@marble folio i tried but not works
because that's not how you make a Readable
fs.createReadStream(path[, options])
Unlike the 16 KiB default highWaterMark for a <stream.Readable>, the stream returned by this method has a default highWaterMark of 64 KiB.options can include start and end values to read a range of bytes from the file instead of the entire file.
for example with that
otherwise you'd have to actually implement the read() method and not leave it empty
i have to write the push in it?
No. You‘d actually have to return what the stream yields on each read. Which you probably don’t want to do yourself
🫠
Use that instead. That accepts a Buffer and returns a Readable
ok, and for the method read()?
By using 👆you already have a Readable, which has a read() method. You wouldn’t have to implement anything
const readable = fs.createReadStream(filepath);
callCharacter.output.on("frameReceived", ev => {
readable.push(Buffer.from(ev.frame.data.buffer));
readable.push(null)
});
player.play(createAudioResource(readable, {silencePaddingFrames: 5}));
right now? @fleet coyote
What kinda filepath did you pass in there? You should pass your buffer to the function directly, no need to push
like that "readable = createReadStream(Buffer.from(ev.frame.data.buffer));"
?
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string, Uint8Array, or URL without null bytes.
@fleet coyote