I typed a code in Python that creates a TCP server and to publish the system sound with my phone.
import socket
import soundcard as sc
def get_host_ip():
try:
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
return host_ip
except:
return '127.0.0.1'
HOST = get_host_ip()
PORT = 1010
SAMPLE_RATE = 48000
RECORD_SEC = 5
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket:
server_socket.bind((HOST, PORT))
server_socket.listen()
print(f"TCP Server is listening on {HOST}:{PORT}...")
while True:
conn, addr = server_socket.accept()
with conn:
print(f'Connected: {addr[0]}:{addr[1]}')
with sc.get_microphone(id=str(sc.default_speaker().name), include_loopback=True).recorder(samplerate=SAMPLE_RATE) as mic:
data = mic.record(numframes=SAMPLE_RATE * RECORD_SEC)
conn.sendall(data[:, 0])
and for my phone I want to create a Flutter app that takes the bytes and plays. How can I do that and should I change the Python code?
I tried come codes in Internet and asked AI. But nothing.