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

receive audio from multiple users and send at same time #84

Open
sebastianmaisel opened this issue Sep 22, 2020 · 6 comments
Open

receive audio from multiple users and send at same time #84

sebastianmaisel opened this issue Sep 22, 2020 · 6 comments

Comments

@sebastianmaisel
Copy link

sebastianmaisel commented Sep 22, 2020

Hi,
I'm working with pymumble to communicate with a various number of users who also are using pymumble.

So it's not only sending audio (microphone) to murmur-server but also receiving audio from different users via pymumble and outputting that to a speaker.

At the moment I'm asking for all online users in an endless while-loop and adding the soundchunk of every user by using audioop.add.

When done for every user, the PCM-chunk will be written to speaker.
As I notice that works but seems to have really bad performance when increasing number of speaking users at the same time. I would like to record a whole channel with more than 20 users, which seems to be impossible with that method.

Do you have alternative, better options to "mix" the sound of all users together and bring it to speaker with low latency?

Thanks for any help! :-)

@azlux
Copy link
Owner

azlux commented Oct 6, 2020

Hi,
Can you put the part of the bot you use for the user voice parsing ?
I suppose you use the callback PYMUMBLE_CLBK_SOUNDRECEIVED function.
Maybe you will have better performance with a loop to receive the sound of all users : https://github.com/azlux/pymumble/blob/pymumble_py3/API.md#soundqueue-object-accessible-through-usersound

Sound is not merge together, but this function have buffer waiting for some loop to take the sound data, maybe it will help.

To be honest, I've never used it with more than 6 users.

@sebastianmaisel
Copy link
Author

sebastianmaisel commented Oct 6, 2020

Thanks for your answer, @azlux !
No, I don't use the Callback. How does the Callback work with more than one user? Will it merge all users together by itself? Didn't understand that function yet.

At the moment my implementation works in a sound_receive-function which runs endless in a thread.
https://pastebin.com/2Ba6rcbe

@azlux
Copy link
Owner

azlux commented Oct 6, 2020

In fact, the callback will be trigger user by user. So you also need to merge the sound manually (

self.callbacks(PYMUMBLE_CLBK_SOUNDRECEIVED, self.users[session.value], newsound)
)
Using a callback isn't better, there are a little bit less calculation to do on the library side, but I think your bottleneck is to merge and send the audio to the speaker ?

@sebastianmaisel
Copy link
Author

Yes, I guess that's the bottleneck.
It seems that every new user in the system is increasing the CPU usage pretty much.

Could it be a problem that I'm using the threading module to handle GUI, transmitting and receiving audio at the same time or shouldn't there be any connection with that method?
Generally, is there any example implementation of using pymumble in receiving and transmitting mode simultaneously?

@azlux
Copy link
Owner

azlux commented Oct 12, 2020

Sorry I don't have example.
You can use a profiler library to find the bottleneck of your code ( example )
Using a thread to manage input and output separately in the same time is also a good idea.

@azlux
Copy link
Owner

azlux commented Oct 29, 2020

Do you have any news about the tests ?

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