class Client(): def __init__(self, master): self.microphone = Microphone() self.audioToNet = AudioToNet() self.trafficPrinter = TrafficPrinter() self.master = master def call(self, host, port): self.microphone.init() s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.master.serveOn(s) self.sendTo(s, host, port) self.microphone.destroy() def sendTo(self, socket, host, port): print "Sending to {0}, port {1}".format(host, port) while True: audio = self.microphone.nextAudioChunk() chunk = self.audioToNet.convert(audio) self.sendChunk(chunk, socket, host, port) def sendChunk(self, chunk, socket, host, port): socket.sendto(chunk, (host, port)) self.trafficPrinter.addTraffic(len(chunk))
def init(): # only required for blitting to give a clean slate. x_data = np.arange(VISUALIZER_LENGTH) y_data = np.zeros(len(x_data)) line.set_data(x_data, y_data) return line, def animate(i): x_data = np.arange(VISUALIZER_LENGTH) y_data = np.zeros(len(x_data)) raw_data = mic.sampleInput() if sum(raw_data) > 0: processed_data = sig_processor.process_sample(raw_data) y_data = np.concatenate((processed_data[::-1], processed_data)) y_data = y_data / y_data.mean() x_data = np.arange(len(y_data)) line.set_data(x_data, y_data) return line, ani = animation.FuncAnimation(fig, animate, blit=True, init_func=init, frames=10, interval=10) plt.show() mic.destroy()