voice icon indicating copy to clipboard operation
voice copied to clipboard

Record Audio (Simple Example)

Open Yvtq8K3n opened this issue 3 years ago • 1 comments

I have no idea why the v11 and bellow examples are so much more simple than this. Splitting the files just makes it hard to interpret this.

Yvtq8K3n avatar Sep 29 '21 15:09 Yvtq8K3n

`// Join with selfDeaf set to false to receive audio
const voiceConnection = joinChannel({ ...options, selfDeaf: false });

voiceConnection.receiver.speaking.on('start', userId => console.log(`User ${userId} started speaking`));
voiceConnection.receiver.speaking.on('end', userId => console.log(`User ${userId} stopped speaking`));

// A Readable object mode stream of Opus packets
// Will only end when the voice connection is destroyed
voiceConnection.receiver.subscribe(userId);

// A Readable object mode stream of Opus packets
// Will end when the voice connection is destroyed, or the user has not said anything for 100ms
const opusStream = voiceConnection.receiver.subscribe(userId, {
  end: {
    behavior: EndBehaviorType.AfterSilence,
    duration: 100,
  },
});

// -------------------------

// You can re-use the Opus stream, e.g. to play in another channel as an echo
const resource = createAudioResource(opusStream, { inputType: StreamType.Opus });

// You can decode the Opus stream to raw audio using prism-media
const rawAudio = opusStream.pipe(new prism.opus.Decoder({ frameSize: 960, channels: 2, rate: 48000 }));

// You can save the stream to an Ogg file using [email protected]
const oggWriter = new opus.OggLogicalBitstream({
  opusHead: new opus.OpusHead({
    channelCount: 2,
    sampleRate: 48000,
  }),
  pageSizeControl: {
    maxPackets: 10,
  },
});

pipeline(opusStream, oggWriter, createWriteStream('./myfile.ogg'), callback);`

This should be present in here.

Yvtq8K3n avatar Sep 29 '21 15:09 Yvtq8K3n