Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Playing around with streamer settings, adding a client for the tcp st…

…reamer
  • Loading branch information...
commit fdeea7c64b304996b13f4e15721c22602fe58b45 1 parent ab3ddc5
Jeremy Grosser authored
Showing with 45 additions and 6 deletions.
  1. +13 −6 streamer.py
  2. +32 −0 tcpclient.py
19 streamer.py
View
@@ -1,6 +1,8 @@
from subprocess import Popen, PIPE
+from threading import Thread
from socket import *
from time import clock
+import aifc
import struct
import sys
@@ -21,25 +23,30 @@
mreq = struct.pack('4sl', inet_aton('224.0.1.20'), INADDR_ANY)
sock.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
-#decoder = '/usr/local/bin/lame - -'
+#decoder = '/usr/local/bin/lame --decode - -'
decoder = '/bin/cat'
-#p = Popen(decoder.split(' '), stdin=PIPE, stdout=PIPE)
+p = Popen(decoder.split(' '), stdin=PIPE, stdout=PIPE)
def read_stream():
while True:
- audio.write(sock.recv(CHUNKSIZE))
+ #p.stdin.write(sock.recv(CHUNKSIZE))
+ data = sock.recv(CHUNKSIZE)
+ audio.write(data)
#sys.stdout.write(data)
#p.stdin.write(data)
def play_stream():
while True:
- data = p.stdout.read()
- audio.write(data)
+ audio.write(p.stdout.read(CHUNKSIZE))
#t = Thread(target=read_stream)
#t.setDaemon(True)
#t.start()
-#play_stream()
read_stream()
+
+#t1 = Thread(target=play_stream)
+#t1.setDaemon(True)
+#t1.start()
+
32 tcpclient.py
View
@@ -0,0 +1,32 @@
+from subprocess import Popen, PIPE
+from threading import Thread
+from socket import *
+from time import clock
+import aifc
+import struct
+import sys
+
+import pyaudio
+
+CHUNKSIZE = 1024
+pa = pyaudio.PyAudio()
+
+stream_info = pyaudio.PaMacCoreStreamInfo(flags=pyaudio.PaMacCoreStreamInfo.paMacCorePlayNice, channel_map=(0, 1))
+audio = pa.open(format=pyaudio.paInt16,
+ channels=1,
+ rate=48000,
+ output=True,
+ output_host_api_specific_stream_info=stream_info)
+
+sock = socket()
+sock.connect(('127.0.0.1', 9201))
+
+def read_stream():
+ while True:
+ #p.stdin.write(sock.recv(CHUNKSIZE))
+ data = sock.recv(CHUNKSIZE)
+ audio.write(data)
+ #sys.stdout.write(data)
+ #p.stdin.write(data)
+
+read_stream()
Please sign in to comment.
Something went wrong with that request. Please try again.