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

Unable to create oggStream #210

Open
Yvtq8K3n opened this issue Sep 29, 2021 · 2 comments
Open

Unable to create oggStream #210

Yvtq8K3n opened this issue Sep 29, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@Yvtq8K3n
Copy link

Yvtq8K3n commented Sep 29, 2021

member.guild.channels.cache.get(voiceChannel.id).members.forEach((tempMember) => {
                const filename = './recordings/${Date.now()}-${tempMember.id}.ogg';

                const opusStream = receiver.subscribe(tempMember.id, {
                    end: {
                      behavior: EndBehaviorType.AfterSilence,
                      duration: 100,
                    },
                  });
         
                //const rawAudio = opusStream.pipe(new opus.Decoder({ frameSize: 960, channels: 2, rate: 48000 }));
                
                const oggStream = new opus.OggLogicalBitstream({
                    opusHead: new opus.OpusHead({
                        channelCount: 2,
                        sampleRate: 48000,
                    }),
                    opusTags: new opus.OpusTags({
                        maxPackets: 10,
                    })
                });
                
                
                const out = fs.createWriteStream(filename);

                pipeline(opusStream, oggStream, out,  (err) => {
                    console.log(err);
                    if (err) {
                        console.warn('❌ Error recording file ${filename} - ${err.message}');
                    } else {
                        console.log('✅ Recorded ${filename}');
                    }
                });
            });
        }

TypeError: failed to downcast any to number
at crc (C:\Users\Yvtq8\Desktop\SideProjects\BobbyMcLovin\node_modules\node-crc\lib\lib.js:11:17)
at OggLogicalBitstream.calculateCRC (C:\Users\Yvtq8\Desktop\SideProjects\BobbyMcLovin\node_modules\prism-media\dist\ogg\OggLogicalBitstream.js:92:23)
at OggLogicalBitstream.writePage (C:\Users\Yvtq8\Desktop\SideProjects\BobbyMcLovin\node_modules\prism-media\dist\ogg\OggLogicalBitstream.js:150:33)
at OggLogicalBitstream.writeHeaderPages (C:\Users\Yvtq8\Desktop\SideProjects\BobbyMcLovin\node_modules\prism-media\dist\ogg\OggLogicalBitstream.js:74:18)
at new OggLogicalBitstream (C:\Users\Yvtq8\Desktop\SideProjects\BobbyMcLovin\node_modules\prism-media\dist\opus\OggLogicalBitstream.js:16:14)
at C:\Users\Yvtq8\Desktop\SideProjects\BobbyMcLovin\index.js:51:35
at Map.forEach ()
at start (C:\Users\Yvtq8\Desktop\SideProjects\BobbyMcLovin\index.js:37:70)

@Yvtq8K3n Yvtq8K3n added the bug Something isn't working label Sep 29, 2021
@odysseaspapadimas
Copy link

Any updates on this? Or some alternative so I can record in a voice channel and output it?

@Yvtq8K3n
Copy link
Author

Yvtq8K3n commented Oct 30, 2021

Any updates on this? Or some alternative so I can record in a voice channel and output it?

I did manage to find a way to successfully record and store voice recordings. However, I have no clue how it works.
First, I made a class called Decoder, as follows:
`
class OpusDecodingStream extends Transform {
encoder

constructor(options, encoder) {
    super(options)
    this.encoder = encoder
}

_transform(data, encoding, callback) {
    this.push(this.encoder.decode(data))
    callback()
}

}
`
Then with this decoder, which I still have no clue how it works, I parsed the audio and was able to store it.

await entersState(connection, VoiceConnectionStatus.Ready, 20e3);
		if (connection) {	    
            const receiver = connection.receiver;
            member.guild.channels.cache.get(voiceChannel.id).members.forEach((tempMember) => {
                const username = findUsername(tempMember.id)
                const filename = "./recordings/test_${Date.now()}_${username}.wav";

                const encoder = new OpusEncoder(16000, 1)
                const commandAudioStream = receiver.subscribe(tempMember.id, {
                    end: {
                      behavior: EndBehaviorType.AfterSilence,
                      duration: 100,
                    },
                })
                .pipe(new OpusDecodingStream({}, encoder))
                .pipe(new FileWriter(filename, {
                    channels: 1,
                    sampleRate: 16000
                }))
            });

Hopes this helps, but I really would like to see a cleaner guide. Not everyone is an audio engineer;( It would be nice to know how to store in other audio formats.
You can see the full code in here: https://github.com/Yvtq8K3n/BobbyMcLovin/blob/742d041f5d3bd621628681c9ded0d7acde096c24/index.js#L72-L84

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants