bot.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import pymumble_py3 as pymumble
  2. from pymumble_py3.callbacks import PYMUMBLE_CLBK_SOUNDRECEIVED as PCS
  3. import subprocess as sp
  4. from time import sleep
  5. import sys
  6. import os
  7. import fcntl
  8. import pyaudio
  9. pwd = "" # password
  10. server = "mumble.esiliati.org" # server address
  11. nick = "TubiaBot"
  12. channel = "radiospore"
  13. port = 64738 # port number
  14. # pyaudio set up
  15. CHUNK = 1024
  16. FORMAT = pyaudio.paInt16 # pymumble soundchunk.pcm is 16 bits
  17. CHANNELS = 1
  18. RATE = 48000 # pymumble soundchunk.pcm is 48000Hz
  19. # mumble client set up
  20. def sound_received_handler(user, soundchunk):
  21. """ play sound received from mumble server upon its arrival """
  22. sys.stdout.buffer.write(soundchunk.pcm)
  23. # Spin up a client and connect to mumble server
  24. mumble = pymumble.Mumble(server, nick, password=pwd, port=port)
  25. # set up callback called when PCS event occurs
  26. mumble.callbacks.set_callback(PCS, sound_received_handler)
  27. mumble.set_receive_sound(1) # Enable receiving sound from mumble server
  28. mumble.start()
  29. mumble.is_ready() # Wait for client is ready
  30. mumble.channels.find_by_name(channel).move_in()
  31. mumble.users.myself.mute()
  32. # constant capturing sound and sending it to mumble server
  33. while True:
  34. sleep(0.1)