diff --git a/Requirements.txt b/Requirements.txt new file mode 100644 index 0000000..a4ee4ee --- /dev/null +++ b/Requirements.txt @@ -0,0 +1 @@ +pymumble diff --git a/garmr.py b/garmr.py new file mode 100755 index 0000000..2a66995 --- /dev/null +++ b/garmr.py @@ -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() diff --git a/modules/__init__.py b/modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/custom_mumble.py b/modules/custom_mumble.py new file mode 100644 index 0000000..4ea755c --- /dev/null +++ b/modules/custom_mumble.py @@ -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