Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting member from listener #12

Open
gutbash opened this issue Apr 17, 2024 · 1 comment
Open

getting member from listener #12

gutbash opened this issue Apr 17, 2024 · 1 comment

Comments

@gutbash
Copy link

gutbash commented Apr 17, 2024

    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
Copy link

for commented Aug 4, 2024

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.

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

No branches or pull requests

2 participants