commit b5c25239a06c6f1a7dcf9bcb3f610f3c5f3610a0 Author: pstruebi Date: Wed May 21 11:21:38 2025 +0200 initial commit diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ff5300e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.languageServer": "None" +} \ No newline at end of file diff --git a/audio_sink.py b/audio_sink.py new file mode 100644 index 0000000..b407d4b --- /dev/null +++ b/audio_sink.py @@ -0,0 +1,19 @@ +import socket +import sounddevice as sd +import numpy as np + +PORT = 50007 +SAMPLERATE = 44100 +CHANNELS = 1 +CHUNK = 1024 + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +sock.bind(('0.0.0.0', PORT)) + +def audio_callback(outdata, frames, time, status): + data, _ = sock.recvfrom(CHUNK * 2) # 2 bytes per sample (int16) + outdata[:] = np.frombuffer(data, dtype=np.int16).reshape(-1, CHANNELS) + +with sd.OutputStream(samplerate=SAMPLERATE, channels=CHANNELS, dtype='int16', blocksize=CHUNK, callback=audio_callback): + print("Receiving audio...") + input() # Press Enter to stop \ No newline at end of file diff --git a/audio_source.py b/audio_source.py new file mode 100644 index 0000000..1f85b43 --- /dev/null +++ b/audio_source.py @@ -0,0 +1,19 @@ +import socket +import sounddevice as sd +import numpy as np + +# Settings +IP = '10.42.0.231' # when rpi is connected to the ethernet socket of the laptop +PORT = 50007 +SAMPLERATE = 44100 +CHANNELS = 1 +CHUNK = 1024 + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + +def callback(indata, frames, time, status): + sock.sendto(indata.tobytes(), (IP, PORT)) + +with sd.InputStream(samplerate=SAMPLERATE, channels=CHANNELS, blocksize=CHUNK, callback=callback): + print("Streaming audio...") + input() # Press Enter to stop \ No newline at end of file