mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
reformatting
This commit is contained in:
@@ -64,7 +64,6 @@ async def main():
|
|||||||
ping_pong=args.ping_pong
|
ping_pong=args.ping_pong
|
||||||
)
|
)
|
||||||
await sc.start()
|
await sc.start()
|
||||||
print("Stream client started")
|
|
||||||
async for msg in sc.get_reader():
|
async for msg in sc.get_reader():
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import wave
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
import jax.numpy as jnp
|
import jax.numpy as jnp
|
||||||
|
import requests
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription
|
from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription
|
||||||
from aiortc.contrib.media import MediaRelay
|
from aiortc.contrib.media import MediaRelay
|
||||||
@@ -77,7 +78,8 @@ def get_transcription():
|
|||||||
wf.close()
|
wf.close()
|
||||||
|
|
||||||
whisper_result = pipeline(out_file.getvalue())
|
whisper_result = pipeline(out_file.getvalue())
|
||||||
item = { 'text': whisper_result["text"],
|
item = {
|
||||||
|
'text': whisper_result["text"],
|
||||||
'start_time': str(frames[0].time),
|
'start_time': str(frames[0].time),
|
||||||
'time': str(datetime.datetime.now())
|
'time': str(datetime.datetime.now())
|
||||||
}
|
}
|
||||||
@@ -89,7 +91,7 @@ def get_transcription():
|
|||||||
|
|
||||||
class AudioStreamTrack(MediaStreamTrack):
|
class AudioStreamTrack(MediaStreamTrack):
|
||||||
"""
|
"""
|
||||||
A video stream track that transforms frames from an another track.
|
An audio stream track to send audio frames.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
kind = "audio"
|
kind = "audio"
|
||||||
@@ -109,15 +111,13 @@ def start_messaging_thread():
|
|||||||
message_thread.start()
|
message_thread.start()
|
||||||
|
|
||||||
|
|
||||||
def start_transcription_thread(max_threads):
|
def start_transcription_thread(max_threads: int):
|
||||||
t_threads = []
|
|
||||||
for i in range(max_threads):
|
for i in range(max_threads):
|
||||||
t_thread = threading.Thread(target=get_transcription, args=(i,))
|
t_thread = threading.Thread(target=get_transcription, args=(i,))
|
||||||
t_threads.append(t_thread)
|
|
||||||
t_thread.start()
|
t_thread.start()
|
||||||
|
|
||||||
|
|
||||||
async def offer(request):
|
async def offer(request: requests.Request):
|
||||||
params = await request.json()
|
params = await request.json()
|
||||||
offer = RTCSessionDescription(sdp=params["sdp"], type=params["type"])
|
offer = RTCSessionDescription(sdp=params["sdp"], type=params["type"])
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ async def offer(request):
|
|||||||
pc_id = "PeerConnection(%s)" % uuid.uuid4()
|
pc_id = "PeerConnection(%s)" % uuid.uuid4()
|
||||||
pcs.add(pc)
|
pcs.add(pc)
|
||||||
|
|
||||||
def log_info(msg, *args):
|
def log_info(msg: str, *args):
|
||||||
logger.info(pc_id + " " + msg, *args)
|
logger.info(pc_id + " " + msg, *args)
|
||||||
|
|
||||||
log_info("Created for %s", request.remote)
|
log_info("Created for %s", request.remote)
|
||||||
@@ -138,7 +138,7 @@ async def offer(request):
|
|||||||
start_time = datetime.datetime.now()
|
start_time = datetime.datetime.now()
|
||||||
|
|
||||||
@channel.on("message")
|
@channel.on("message")
|
||||||
def on_message(message):
|
def on_message(message: str):
|
||||||
channel_log(channel, "<", message)
|
channel_log(channel, "<", message)
|
||||||
if isinstance(message, str) and message.startswith("ping"):
|
if isinstance(message, str) and message.startswith("ping"):
|
||||||
# reply
|
# reply
|
||||||
@@ -164,13 +164,14 @@ async def offer(request):
|
|||||||
await pc.setLocalDescription(answer)
|
await pc.setLocalDescription(answer)
|
||||||
return web.Response(
|
return web.Response(
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
text=json.dumps(
|
text=json.dumps({
|
||||||
{ "sdp": pc.localDescription.sdp, "type": pc.localDescription.type }
|
"sdp": pc.localDescription.sdp,
|
||||||
),
|
"type": pc.localDescription.type
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def on_shutdown(app):
|
async def on_shutdown(app: web.Application):
|
||||||
coros = [pc.close() for pc in pcs]
|
coros = [pc.close() for pc in pcs]
|
||||||
await asyncio.gather(*coros)
|
await asyncio.gather(*coros)
|
||||||
pcs.clear()
|
pcs.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user