random/mumble-bot/bot.py
2020-04-06 13:34:51 +02:00

41 lines
1.2 KiB
Python

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"
channel = "radiospore"
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
mumble.channels.find_by_name(channel).move_in()
mumble.users.myself.mute()
# constant capturing sound and sending it to mumble server
while True:
sleep(0.1)