Files
network_audio_streaming/network_audio_streaming/audio_source.py
2025-05-21 12:19:39 +02:00

21 lines
593 B
Python

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
IP = '0.0.0.0' # same as the laptop for local testing
PORT = 50007
SAMPLERATE = 16000
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, dtype='int16', blocksize=CHUNK, callback=callback):
print("Streaming audio...")
input() # Press Enter to stop