Skip to content

Instantly share code, notes, and snippets.

@naoh16
Created February 3, 2021 09:53
Show Gist options
  • Save naoh16/085413edebd21c036a9d13c859c4e930 to your computer and use it in GitHub Desktop.
Save naoh16/085413edebd21c036a9d13c859c4e930 to your computer and use it in GitHub Desktop.
Example script for Julius Adinnet sender for WAV file
#!env python
import wave
import socket
from struct import pack
import time
adinnet_hostname = 'localhost'
adinnet_port = 5530
wav_filename = 'tmp.wav'
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(1.0)
try:
s.connect((adinnet_hostname, adinnet_port))
except OSError as msg:
print(msg)
s.shutdown()
s = None
with wave.open(wav_filename, 'rb') as r:
sz = 1024
while True:
data = r.readframes(sz)
rdsz = pack('i', len(data))
print('{:d} {:d} {:d} {:d} {:d}'.format(len(data), data[0], data[1], data[2], data[3]))
s.sendall(rdsz)
s.sendall(data)
time.sleep(0.1)
rdsz = pack('i', 0)
s.sendall(rdsz)
s.sendall(b'')
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment