this doesn't work yet. May never work lol.

This commit is contained in:
stormdragon2976 2023-06-12 00:20:34 -04:00
parent 0fc58d23cb
commit 91954beafc
4 changed files with 89 additions and 0 deletions

1
Requirements.txt Normal file
View File

@ -0,0 +1 @@
pymumble

60
garmr.py Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env python3
import pymumble_py3
from pymumble_py3.callbacks import PYMUMBLE_CLBK_SOUNDRECEIVED as PCS
import sounddevice as sd
import numpy as np
import threading
import time
from modules.custom_mumble import CustomMumble
from setproctitle import setproctitle
setproctitle("Garmr")
# Connection details for Mumble server
server = "mumble.example.com" # server address
nick = "Garmr_Test"
port = 64738 # port number
passwd = "" # password
# Audio settings
SAMPLE_RATE = 48000
CHANNELS = 2
# Create a Mumble client using the custom wrapper class
mumble = CustomMumble(server, nick, password=passwd, port=port)
mumble.set_application_string("garmr")
# Set the sample rate and channels for Mumble
mumble.set_receive_sound((SAMPLE_RATE, CHANNELS))
# Create a SoundDevice audio handler
audio_handler = sd.OutputStream(samplerate=SAMPLE_RATE, channels=CHANNELS)
# Set the audio handler in the custom Mumble class
mumble.set_audio_handler(audio_handler)
# Set up the sound received callback
mumble.callbacks.set_callback(PCS, mumble.sound_received_handler)
# Start the Mumble client
mumble.start()
mumble.is_ready() # Wait for the client to be ready
# Keep the script running until interrupted
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
# Stop and close the SoundDevice stream
audio_handler.stop()
audio_handler.close()
# Stop the Mumble client
mumble.stop()

0
modules/__init__.py Normal file
View File

28
modules/custom_mumble.py Normal file
View File

@ -0,0 +1,28 @@
import pymumble_py3
import numpy as np
import threading
class CustomMumble(pymumble_py3.Mumble):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.audio_handler = None
self.is_running = False
def set_audio_handler(self, audio_handler):
self.audio_handler = audio_handler
def sound_received_handler(self, user, soundchunk):
if self.audio_handler is not None:
sound_array = np.frombuffer(soundchunk.pcm, dtype=np.int16)
num_channels = self.audio_handler.channels
sound_array = sound_array.reshape((-1, num_channels))
sound_float = sound_array.astype(np.float32) / 32767.0
self.audio_handler.write(sound_float)
def start(self):
self.is_running = True
threading.Thread(target=self.run).start()
def stop(self):
self.is_running = False