random/mumble-bot/bot.py

43 lines
1.2 KiB
Python
Raw Normal View History

2020-04-06 13:29:25 +02:00
import shout
import pymumble_py3 as pymumble
from pymumble_py3.callbacks import PYMUMBLE_CLBK_SOUNDRECEIVED as PCS
import subprocess as sp
from time import sleep
import sys
import os
import fcntl
import pyaudio
pwd = "" # password
server = "mumble.esiliati.org" # server address
nick = "TubiaBot"
2020-04-06 13:34:07 +02:00
channel = "radiospore"
2020-04-06 13:29:25 +02:00
port = 64738 # port number
# pyaudio set up
CHUNK = 1024
FORMAT = pyaudio.paInt16 # pymumble soundchunk.pcm is 16 bits
CHANNELS = 1
RATE = 48000 # pymumble soundchunk.pcm is 48000Hz
# mumble client set up
def sound_received_handler(user, soundchunk):
""" play sound received from mumble server upon its arrival """
sys.stdout.buffer.write(soundchunk.pcm)
# Spin up a client and connect to mumble server
mumble = pymumble.Mumble(server, nick, password=pwd, port=port)
# set up callback called when PCS event occurs
mumble.callbacks.set_callback(PCS, sound_received_handler)
mumble.set_receive_sound(1) # Enable receiving sound from mumble server
mumble.start()
mumble.is_ready() # Wait for client is ready
2020-04-06 13:34:07 +02:00
mumble.channels.find_by_name(channel).move_in()
2020-04-06 13:29:25 +02:00
mumble.users.myself.mute()
# constant capturing sound and sending it to mumble server
while True:
sleep(0.1)