Initial commit of ZonePlayer
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import yaml # type: ignore
|
||||
import sys
|
||||
import jack # type: ignore
|
||||
import socket
|
||||
import numpy as np # type: ignore
|
||||
import time
|
||||
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python3 zone.py <zone_name>")
|
||||
sys.exit(1)
|
||||
|
||||
zone_name = sys.argv[1]
|
||||
|
||||
with open("config.yaml", "r") as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
zone = config["zones"].get(zone_name)
|
||||
|
||||
if not zone:
|
||||
print(f"Zone '{zone_name} not found in config")
|
||||
sys.exit(1)
|
||||
|
||||
jack_input = zone["jack_input"]
|
||||
ip = zone["ip"]
|
||||
port = zone["port"]
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
client = jack.Client(jack_input)
|
||||
client.inports.register("in_l")
|
||||
client.inports.register("in_r")
|
||||
|
||||
def send_pcm_frames(frames: np.ndarray):
|
||||
int16 = (frames * 32767.0).astype(np.int16)
|
||||
interleaved = np.column_stack(int16).ravel()
|
||||
sock.sendto(interleaved.tobytes(), (ip, port))
|
||||
|
||||
@client.set_process_callback
|
||||
def process(frames):
|
||||
l = client.inports[0].get_array()
|
||||
r = client.inports[1].get_array()
|
||||
data = np.vstack((l, r))
|
||||
send_pcm_frames(data)
|
||||
|
||||
with client:
|
||||
print(f"Streaming {zone_name} to {ip}:{port}")
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("Stopped")
|
||||
Reference in New Issue
Block a user