imayhaveborkedit / discord-ext-voice-recv

Voice receive extension package for discord.py
https://pypi.org/project/discord-ext-voice-recv/
MIT License
114 stars 17 forks source link

getting member from listener #12

Open gutbash opened 7 months ago

gutbash commented 7 months ago
    class IvaSink(voice_recv.BasicSink):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)

        @voice_recv.AudioSink.listener()
        def on_voice_member_speaking_start(member: discord.Member):

            print(f"member started speaking")

        @voice_recv.AudioSink.listener()
        def on_voice_member_speaking_stop(member: discord.Member):
            print(f"member stopped speaking")

            user_id = member.id

            try:
                pcm_data = audio_buffer.get(user_id, None)
                if pcm_data:
                    dg_connection.send(pcm_data)
                else:
                    print("No PCM data received")
                audio_buffer[user_id] = b""
            except Exception as e:
                print(e)

why does receiving the member not work like in the read me?

for commented 3 months ago

Not sue if this helps, if not I can show more of my code.

"class AudioSink"

class AudioSink(voice_recv.BasicSink):
    def __init__(self, callback):
        super().__init__(callback)
        self.audio_data = []
        self.speakers = defaultdict(int)
def write(self, user, data: voice_recv.VoiceData):
        self.audio_data.append(data.pcm)  # Extract raw audio data
        self.speakers[str(user)] += 1  # Count how many times each user spoke

"class Recording"

def callback(user, data: voice_recv.VoiceData):
            print(f"Got packet from {user}")
            self.sink.write(user, data)

        vc = await voice_channel.connect(cls=voice_recv.VoiceRecvClient)
        self.sink = AudioSink(callback)
        vc.listen(self.sink)

speaker_info = "\n".join([f"{user}: spoke {count} times" for user, count in self.sink.speakers.items()])

I hope that's everything you need.