Skip to content

Instantly share code, notes, and snippets.

@amicuscertus
Created June 4, 2018 23:01
Show Gist options
  • Save amicuscertus/5cb5f697bef887f0b752636092f5d468 to your computer and use it in GitHub Desktop.
Save amicuscertus/5cb5f697bef887f0b752636092f5d468 to your computer and use it in GitHub Desktop.
import socket
import numpy as np
import pyaudio
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
output=True)
ba = bytearray(CHUNK)
wpnt = 0
UDP_IP = "127.0.0.1"
UDP_PORT = 7355
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(512)
ldata = len(data)
for i in range(ldata):
ba[wpnt] = data[i]
wpnt += 1
if wpnt >= CHUNK:
wpnt = 0
stream.write(bytes(ba))
# end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment