コード例 #1
0
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()
コード例 #2
0
ファイル: rtcaudio.py プロジェクト: dkumor/rtcbot
import asyncio
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)
コード例 #3
0
ファイル: audio.py プロジェクト: dkumor/rtcbot
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()
コード例 #4
0
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)
コード例 #5
0
ファイル: closetest.py プロジェクト: dkumor/rtcbot
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)
コード例 #6
0
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
コード例 #7
0
from aiohttp import web

routes = web.RouteTableDef()

from rtcbot import RTCConnection, getRTCBotJS, CVCamera, Microphone

camera = CVCamera()
mic = Microphone()

# For this example, we use just one global connection
conn = RTCConnection()
conn.video.putSubscription(camera)
conn.audio.putSubscription(mic)


# 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("/")
コード例 #8
0
import asyncio
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)
コード例 #9
0
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()