#i have an arraybuffer how can i trasform it to use in createAudioResource()?

71 messages · Page 1 of 1 (latest)

tacit shard
#

help

thorn leafBOT
#
  • What are your intents? GuildVoiceStates is 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!
marble folio
#

where are you getting an arraybuffer from anyways

#

turn it into a Readable

tacit shard
#

do u have the example code ? i never worked on audio so im very dumb at that

marble folio
tacit shard
#

❤️

tacit shard
# marble folio yes

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);
          }
        });
marble folio
#

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

tacit shard
#

with an ia

marble folio
#

but what is ev.frame

#

@tacit shard what package/website/whatever are you getting the data from

marble folio
#

which is?

tacit shard
marble folio
#

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

tacit shard
marble folio
#

but u only need to do make the readable once if you keep pushing the buffer data to it

tacit shard
#

or are you telling me that by writing it out, the readable is automatically updated once created and also plays the new buffers?

marble folio
#

if you push yes thats how streams work

tacit shard
#

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

marble folio
#

try

tacit shard
#

it saves the data but if i play i can't play it if its null

tacit shard
# marble folio try

since it runs it once and the readable is empty at that time it will not play the audio

marble folio
#

put infinity as option for silence frames

tacit shard
marble folio
#

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

tacit shard
marble folio
tacit shard
#

five is ok?

#

or i need to increment it?

bleak patioBOT
tacit shard
#
     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

fleet coyote
#

because that's not how you make a Readable

tacit shard
#

😭

bleak patioBOT
#

node 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.

fleet coyote
#

for example with that

#

otherwise you'd have to actually implement the read() method and not leave it empty

tacit shard
fleet coyote
#

No. You‘d actually have to return what the stream yields on each read. Which you probably don’t want to do yourself

fleet coyote
tacit shard
fleet coyote
tacit shard
#
    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

fleet coyote
#

What kinda filepath did you pass in there? You should pass your buffer to the function directly, no need to push

tacit shard
#

?

tacit shard
#

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string, Uint8Array, or URL without null bytes.

tacit shard
#

@fleet coyote