Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Record Audio (Simple Example) #209

Open
Yvtq8K3n opened this issue Sep 29, 2021 · 1 comment
Open

Record Audio (Simple Example) #209

Yvtq8K3n opened this issue Sep 29, 2021 · 1 comment

Comments

@Yvtq8K3n
Copy link

Yvtq8K3n commented Sep 29, 2021

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 Yvtq8K3n changed the title TT Record Audio (Simple Example) Sep 29, 2021
@Yvtq8K3n
Copy link
Author

Yvtq8K3n commented Sep 29, 2021

`// 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant