from rtcbot import ( RTCConnection, Microphone, Speaker, CVDisplay, CVCamera, SubscriptionClosed, ) import logging from contextlib import suppress import signal logging.basicConfig(level=logging.DEBUG) m = Microphone() s = Speaker() d = CVDisplay() cam = CVCamera() # cam.subscribe(d) c1 = RTCConnection() c2 = RTCConnection() c1.video.putSubscription(cam) c1.audio.putSubscription(m) c2.video.subscribe(d) c2.audio.subscribe(s)
import asyncio from rtcbot import Microphone, Speaker, CVCamera, CVDisplay import asyncio import functools import os import signal from contextlib import suppress import logging logging.basicConfig(level=logging.DEBUG) s = Speaker() m = Microphone() c = CVCamera() d = CVDisplay() m.subscribe(s) c.subscribe(d) loop = asyncio.get_event_loop() """ def shutdown(signame): print("got signal %s: exit" % signame) loop = asyncio.get_event_loop() loop.stop() for sig in (signal.SIGINT, signal.SIGTERM): loop.add_signal_handler(sig, shutdown, sig)
import asyncio from rtcbot import Microphone, Speaker microphone = Microphone() speaker = Speaker() @microphone.subscribe def onData(data): data = data * 5 if speaker.ready: speaker.put_nowait(data) try: asyncio.get_event_loop().run_forever() finally: microphone.close() speaker.close()
import asyncio from rtcbot import Microphone, Speaker microphone = Microphone() speaker = Speaker() speaker.putSubscription(microphone) try: asyncio.get_event_loop().run_forever() finally: microphone.close() speaker.close()
import asyncio from rtcbot import Websocket, RTCConnection, CVCamera, CVDisplay, Speaker, Microphone flag = 0 camera1 = CVCamera(cameranumber=0) camera2 = CVCamera(cameranumber=2) mic = Microphone() display = CVDisplay() speaker = Speaker() # For this example, we use just one global connection conn = RTCConnection() conn.video.putSubscription(camera1) conn.audio.putSubscription(mic) display.putSubscription(conn.video.subscribe()) speaker.putSubscription(conn.audio.subscribe()) async def receiver(): global flag while True: if flag: frameSubscription = camera2.subscribe() else: frameSubscription = camera1.subscribe() frame = await frameSubscription.get() conn.video.put_nowait(frame) @conn.subscribe def onMessage(msg): # Called when each message is sent
from aiohttp import web routes = web.RouteTableDef() from rtcbot import RTCConnection, getRTCBotJS, CVDisplay, Speaker display = CVDisplay() speaker = Speaker() # For this example, we use just one global connection conn = RTCConnection() display.putSubscription(conn.video.subscribe()) speaker.putSubscription(conn.audio.subscribe()) # Serve the RTCBot javascript library at /rtcbot.js @routes.get("/rtcbot.js") async def rtcbotjs(request): return web.Response(content_type="application/javascript", text=getRTCBotJS()) # This sets up the connection @routes.post("/connect") async def connect(request): clientOffer = await request.json() serverResponse = await conn.getLocalDescription(clientOffer) return web.json_response(serverResponse) @routes.get("/") async def index(request):
from rtcbot import Microphone, Speaker import asyncio import logging logging.basicConfig(level=logging.DEBUG) m = Microphone() s = Speaker() s.playStream(m) async def testme(): await asyncio.sleep(5) s.stop() m.unsubscribe() asyncio.ensure_future(testme()) asyncio.get_event_loop().run_forever()
from rtcbot import Microphone, Speaker, CVCamera, CVDisplay import asyncio import logging logging.basicConfig(level=logging.DEBUG) m = Microphone() s = Speaker() c = CVCamera() d = CVDisplay() s.putSubscription(m) d.putSubscription(c) @c.onReady def ready(): print("LOL READY") @d.onError def err(e): print("ERR", e) asyncio.get_event_loop().run_forever()