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

Foir the echobot.py example, how would I send the bot to a certain channel and add a delay? #134

Open
minnixtx opened this issue Aug 28, 2023 · 1 comment

Comments

@minnixtx
Copy link

For this example: https://github.com/azlux/pymumble/blob/pymumble_py3/examples/echobot.py I'd like to have the bot move to an "audio test" channel on my mumble server and add a delay of about 10 seconds between the user's audio and the bot's repeated audio. Currently it sits in root and the echo is immediate. I'd like for this to help users test their audio before joining other rooms.

@gitgrub
Copy link

gitgrub commented Sep 15, 2023

Based on echobot.py, free to go to the examples section:
For the echo delay, change echo_timer accordingly.

# This bot sends any sound it receives back to where it has come from.
# Based on echobot.py
import pymumble_py3
from pymumble_py3.callbacks import PYMUMBLE_CLBK_SOUNDRECEIVED as PCS
import time


pwd = ""
server = ""
port = 12345
nick = "Bob"
sound = {
    "buffer": b"",
    "last_time": 0.0,
    "echo_timer": 0.5
}


def sound_received_handler(user, sound_chunk):
    sound["buffer"] += sound_chunk.pcm
    sound["last_time"] = time.time()


def sound_send():
    print("sound buffer size:", len(sound["buffer"]))
    mumble.sound_output.add_sound(sound["buffer"])
    sound["buffer"] = b""


def echo_ready():
    if sound["buffer"] != b"" and time.time() - sound["last_time"] >= sound["echo_timer"]:
        return True


def init_mumble(channel="Root"):
    _mumble = pymumble_py3.Mumble(server, nick, password=pwd, port=port)
    _mumble.callbacks.set_callback(PCS, sound_received_handler)
    _mumble.set_receive_sound(1)
    _mumble.start()
    _mumble.is_ready()
    _mumble.channels.find_by_name(channel).move_in()
    return _mumble


if __name__ == "__main__":
    mumble = init_mumble(channel="Eingangshalle")
    while 1:
        time.sleep(0.2)
        if echo_ready():
            sound_send()

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