How do I create a continuous opus stream?
I want to pipe data into an opusstream and play that opusstream continuously so can then do something like this. Only way I see doing that is through receiver.subscribe(...); but in my case, it's not really practical. Here is a small example of what I want to do:
let opusStream = //what do I enter here?
mixer.pipe(opusStream);
const audioPlayer = createAudioPlayer();
connection.subscribe(audioPlayer);
const resource = createAudioResource(opusStream, { inputType: StreamType.Opus });
audioPlayer.play(resource);
I get the data through a speaking event which then fires the following code:
function playStream(receiver, userId) {
const audioStream = receiver.subscribe(userId, { end: { behavior: EndBehaviorType.AfterSilence, duration: 200 } });
const input = mixer.input({ volume: 75 });
audioStream .on("data", (chunk) => { const buffer = encoder.decode(chunk); input.write(buffer); }) .on("error", (err) => { console.log(err) }) .on("end", () => { mixer.removeInput(input); }); } And "mixer" is then the stream which I want to output, since it mixes all user receiver together into one stream.
audioStream .on("data", (chunk) => { const buffer = encoder.decode(chunk); input.write(buffer); }) .on("error", (err) => { console.log(err) }) .on("end", () => { mixer.removeInput(input); }); } And "mixer" is then the stream which I want to output, since it mixes all user receiver together into one stream.
2 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
[email protected], node v18.14.1
"encoder" on encoder.decode(chunk) is defined as a new OpusEncoder:
const encoder = new OpusEncoder(48000, 2);
Update: I just found it out. It's a simple AudioReceiveStream
let opusStream = new AudioReceiveStream({
end: EndBehaviorType.Manual
});