def audioThread(): firstAudio = True audioStream = None audioDevice = pyaudio.PyAudio() # Activate the audio stream audioPort = ManifoldPython.addMulticastSink(audioTopic) if (audioPort == -1): print("Failed to activate audio stream") ManifoldPython.stop() sys.exit() while not audioThreadExit: ret, data, samples, timestamp = ManifoldPython.getMulticastData( audioPort) if not ret: time.sleep(0.001) continue try: jsonObj = json.loads(data) if firstAudio: firstAudio = False audioStream = audioDevice.open(format=pyaudio.paInt16, channels=int( jsonObj[adefs.CHANNELS]), rate=int(jsonObj[adefs.RATE]), output=True) audioStream.write(samples) except: print("audio data error", sys.exc_info()[0], sys.exc_info()[1]) try: audioStream.stop_stream() audioStream.close() except: pass audioDevice.terminate() ManifoldPython.removeService(audioPort)
# wake up the console print("sensorview starting...") sys.stdout.flush() topicMap[inTopic] = srecs.SensorRecords(inTopic, plotInterval) # start up the plotter sensorPlot = splot.sensorplot() # lastPlotTime is used to control plot updates lastPlotTime = time.time() - plotInterval # Activate the sensor stream inPort = ManifoldPython.addMulticastSink(inTopic) if (inPort == -1): print("Failed to activate sensor stream") ManifoldPython.stop() sys.exit() try: while True: processReceivedMessage() if (time.time() - lastPlotTime) >= plotInterval: lastPlotTime = time.time() sensorPlot.plot(topicMap.values()) time.sleep(0.05) except: pass
# this delay is necessary to allow Qt startup to complete time.sleep(1.0) # wake up the console print("ttytest starting...") sys.stdout.flush() # Activate the client endpoint ttyOutPort = ManifoldPython.addE2EClient(ttyOutTopic) if (ttyOutPort == -1): print("Failed to activate E2E client endpoint") ManifoldPython.stop() sys.exit() # Activate the multicast endpoint ttyInPort = ManifoldPython.addMulticastSink(ttyInTopic) if (ttyInPort == -1): print("Failed to activate multicast sink endpoint") ManifoldPython.stop() sys.exit() ManifoldPython.startConsoleInput() print("Type characters to send:") try: while True: time.sleep(0.001) processReceivedText() c = ManifoldPython.getConsoleInput()
# wake up the console print("avview starting...") sys.stdout.flush() pygame.init() myfont = pygame.font.SysFont("monospace", 18) # start audio thread audioThreadExit = False audioThreadObject = threading.Thread(target=audioThread) audioThreadObject.start() # Activate the video stream videoPort = ManifoldPython.addMulticastSink(videoTopic) if (videoPort == -1): print("Failed to activate video stream") ManifoldPython.stop() sys.exit() lastTime = time.time() try: while True: delta = time.time() - lastTime if (delta) >= 1.0: lastTime = time.time() frameRate = int(float(frameCount) / (delta - 0.01)) frameCount = 0 processVideoMessage()
# this delay is necessary to allow Qt startup to complete time.sleep(1.0) # wake up the console print("ttstest starting...") sys.stdout.flush() # Activate the client endpoint clientPort = ManifoldPython.addE2EClient(textTopic) if (clientPort == -1): print("Failed to activate E2E client endpoint") ManifoldPython.stop() sys.exit() # Activate the sink endpoint sinkPort = ManifoldPython.addMulticastSink(completionTopic) if (sinkPort == -1): print("Failed to activate multicast sink endpoint") ManifoldPython.stop() sys.exit() lastSendTime = time.time() textMessage = rdf.newPublishMessage('tts', textTopic, ttsdefs.DATATYPE, time.time()) textMessage[ttsdefs.TEXT] = testText try: while(True): # main loop processCompletion()
def forwardThread(): global processingForward, forwardMessage, forwardImage, forwardTS, forwardThreadExit, inPort # start ManifoldPython running ManifoldPython.start("facerec", sys.argv, False) # this delay is necessary to allow Qt startup to complete time.sleep(1.0) # Activate the input stream inPort = ManifoldPython.addMulticastSink(inTopic) if (inPort == -1): print("Failed to activate input stream") ManifoldPython.stop() sys.exit() # Activate the output stream outPort = ManifoldPython.addMulticastSource(outTopic) if (outPort == -1): print("Failed to activate output stream") ManifoldPython.stop() sys.exit() while not forwardThreadExit: time.sleep(0.01) processReceivedMessage() if not processingForward: continue try: image = forwardImage inJpeg = np.frombuffer(image, dtype=np.uint8) cv2Image = cv2.imdecode(inJpeg, cv2.IMREAD_COLOR) except: print ("Forward jpeg error", sys.exc_info()[0],sys.exc_info()[1]) try: dataLock.acquire() for detectedData in globalDetectedData: name = detectedData['name'] namepos = detectedData['namepos'] cv2.putText(cv2Image, name, namepos, cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.75, color=(152, 255, 204), thickness=2) landMarks = detectedData['landmarks'] for landMark in landMarks: cv2.circle(cv2Image, center=landMark, radius=3, color=(102, 204, 255), thickness=-1) except: pass dataLock.release() # generate the output jpeg retVal, outJpeg = cv2.imencode('.jpeg', cv2Image) forwardMessage[rtndefs.TOPIC] = outTopic if ManifoldPython.isServiceActive(outPort) and ManifoldPython.isClearToSend(outPort): ManifoldPython.sendMulticastData(outPort, json.dumps(forwardMessage), outJpeg, forwardTS) processingForward = False ManifoldPython.removeService(inPort) ManifoldPython.removeService(outPort) ManifoldPython.stop()