1
0

bot.py 1.2 KB

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