Skip to content

Instantly share code, notes, and snippets.

@abhigenie92
Last active April 7, 2016 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abhigenie92/d328edf766ad18b881f443ad65cee601 to your computer and use it in GitHub Desktop.
Save abhigenie92/d328edf766ad18b881f443ad65cee601 to your computer and use it in GitHub Desktop.
from twisted.internet.protocol import Protocol, ClientFactory
import pdb
# audio imports
import pyaudio,wave
class AudioClientFactory(ClientFactory):
def __init__(self, canvas_obj):
self.canvas_obj = canvas_obj
def buildProtocol(self, addr):
return StrokeClient(self)
class AudioClient(Protocol):
#audio parameters
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
def __init__(self, factory):
self. factory = factory
self.recv_data=''
self.pyaudio_obj=pyaudio.PyAudio()
self.stream=pyaudio_obj.open(format=self.FORMAT,channels=self.CHANNELS,rate=self.RATE,input=True,
frames_per_buffer=self.CHUNK)
self.receive_audio_pyobj=pyaudio.PyAudio()
self.stream_receive = self.receive_audio_pyobj.open(format=self.FORMAT,channels=self.CHANNELS,
rate=self.RATE,output=True)
def connectionMade(self):
print "Connected to remote server"
while True:
audio_data=self.stream.read(self.CHUNK)
self.transport.write(audio_data)
def dataReceived(self,data):
self.stream_receive.write(data)
if __name__ == '__main__':
from twisted.internet import reactor
reactor.connectTCP("127.0.0.1",3036,StrokeClientFactory())
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment