mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
clean up
This commit is contained in:
0
constants.py
Normal file
0
constants.py
Normal file
@@ -14,15 +14,11 @@ from aiortc.contrib.media import MediaRelay
|
|||||||
from av import AudioFifo
|
from av import AudioFifo
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from whisper_jax import FlaxWhisperPipline
|
from whisper_jax import FlaxWhisperPipline
|
||||||
|
|
||||||
from utils.run_utils import run_in_executor
|
from utils.run_utils import run_in_executor
|
||||||
|
|
||||||
transcription = ""
|
|
||||||
|
|
||||||
pcs = set()
|
pcs = set()
|
||||||
relay = MediaRelay()
|
relay = MediaRelay()
|
||||||
data_channel = None
|
data_channel = None
|
||||||
total_bytes_handled = 0
|
|
||||||
pipeline = FlaxWhisperPipline("openai/whisper-tiny",
|
pipeline = FlaxWhisperPipline("openai/whisper-tiny",
|
||||||
dtype=jnp.float16,
|
dtype=jnp.float16,
|
||||||
batch_size=16)
|
batch_size=16)
|
||||||
@@ -30,7 +26,6 @@ pipeline = FlaxWhisperPipline("openai/whisper-tiny",
|
|||||||
CHANNELS = 2
|
CHANNELS = 2
|
||||||
RATE = 48000
|
RATE = 48000
|
||||||
audio_buffer = AudioFifo()
|
audio_buffer = AudioFifo()
|
||||||
start_time = datetime.datetime.now()
|
|
||||||
executor = ThreadPoolExecutor()
|
executor = ThreadPoolExecutor()
|
||||||
|
|
||||||
|
|
||||||
@@ -40,15 +35,8 @@ def channel_log(channel, t, message):
|
|||||||
|
|
||||||
def channel_send(channel, message):
|
def channel_send(channel, message):
|
||||||
# channel_log(channel, ">", message)
|
# channel_log(channel, ">", message)
|
||||||
global start_time
|
|
||||||
if channel:
|
if channel:
|
||||||
channel.send(message)
|
channel.send(message)
|
||||||
print(
|
|
||||||
"Bytes handled :",
|
|
||||||
total_bytes_handled,
|
|
||||||
" Time : ",
|
|
||||||
datetime.datetime.now() - start_time,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_transcription(frames):
|
def get_transcription(frames):
|
||||||
@@ -61,8 +49,6 @@ def get_transcription(frames):
|
|||||||
for frame in frames:
|
for frame in frames:
|
||||||
wf.writeframes(b"".join(frame.to_ndarray()))
|
wf.writeframes(b"".join(frame.to_ndarray()))
|
||||||
wf.close()
|
wf.close()
|
||||||
global total_bytes_handled
|
|
||||||
total_bytes_handled += sys.getsizeof(wf)
|
|
||||||
whisper_result = pipeline(out_file.getvalue(), return_timestamps=True)
|
whisper_result = pipeline(out_file.getvalue(), return_timestamps=True)
|
||||||
with open("test_exec.txt", "a") as f:
|
with open("test_exec.txt", "a") as f:
|
||||||
f.write(whisper_result["text"])
|
f.write(whisper_result["text"])
|
||||||
@@ -111,10 +97,9 @@ async def offer(request):
|
|||||||
|
|
||||||
@pc.on("datachannel")
|
@pc.on("datachannel")
|
||||||
def on_datachannel(channel):
|
def on_datachannel(channel):
|
||||||
global data_channel, start_time
|
global data_channel
|
||||||
data_channel = channel
|
data_channel = channel
|
||||||
channel_log(channel, "-", "created by remote party")
|
channel_log(channel, "-", "created by remote party")
|
||||||
start_time = datetime.datetime.now()
|
|
||||||
|
|
||||||
@channel.on("message")
|
@channel.on("message")
|
||||||
def on_message(message):
|
def on_message(message):
|
||||||
|
|||||||
@@ -12,37 +12,27 @@ from concurrent.futures import ThreadPoolExecutor
|
|||||||
import jax.numpy as jnp
|
import jax.numpy as jnp
|
||||||
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
|
||||||
from av import AudioFifo
|
from av import AudioFifo
|
||||||
from sortedcontainers import SortedDict
|
from sortedcontainers import SortedDict
|
||||||
from whisper_jax import FlaxWhisperPipline
|
from whisper_jax import FlaxWhisperPipline
|
||||||
|
|
||||||
from utils.log_utils import logger
|
from utils.log_utils import logger
|
||||||
from utils.run_utils import Mutex
|
from utils.run_utils import Mutex
|
||||||
|
|
||||||
ROOT = os.path.dirname(__file__)
|
WHISPER_MODEL_SIZE = config['DEFAULT']["WHISPER_REAL_TIME_MODEL_SIZE"]
|
||||||
|
|
||||||
WHISPER_MODEL_SIZE = config['DEFAULT']["WHISPER_MODEL_SIZE"]
|
|
||||||
pcs = set()
|
pcs = set()
|
||||||
relay = MediaRelay()
|
relay = MediaRelay()
|
||||||
data_channel = None
|
data_channel = None
|
||||||
sorted_message_queue = SortedDict()
|
sorted_message_queue = SortedDict()
|
||||||
|
|
||||||
CHANNELS = 2
|
CHANNELS = 2
|
||||||
RATE = 44100
|
RATE = 44100
|
||||||
CHUNK_SIZE = 256
|
CHUNK_SIZE = 256
|
||||||
|
|
||||||
audio_buffer = AudioFifo()
|
|
||||||
pipeline = FlaxWhisperPipline("openai/whisper-" + WHISPER_MODEL_SIZE,
|
pipeline = FlaxWhisperPipline("openai/whisper-" + WHISPER_MODEL_SIZE,
|
||||||
dtype=jnp.float16,
|
dtype=jnp.float16,
|
||||||
batch_size=16)
|
batch_size=16)
|
||||||
|
|
||||||
transcription = ""
|
|
||||||
start_time = datetime.datetime.now()
|
start_time = datetime.datetime.now()
|
||||||
total_bytes_handled = 0
|
|
||||||
|
|
||||||
executor = ThreadPoolExecutor()
|
executor = ThreadPoolExecutor()
|
||||||
|
audio_buffer = AudioFifo()
|
||||||
frame_lock = Mutex(audio_buffer)
|
frame_lock = Mutex(audio_buffer)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ from utils.run_utils import Mutex
|
|||||||
file_lock = Mutex(open("test_sm_6.txt", "a"))
|
file_lock = Mutex(open("test_sm_6.txt", "a"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class StreamClient:
|
class StreamClient:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -46,7 +45,6 @@ class StreamClient:
|
|||||||
self.loop.run_until_complete(self.signaling.close())
|
self.loop.run_until_complete(self.signaling.close())
|
||||||
self.loop.run_until_complete(self.pc.close())
|
self.loop.run_until_complete(self.pc.close())
|
||||||
# self.loop.close()
|
# self.loop.close()
|
||||||
print("ended")
|
|
||||||
|
|
||||||
def create_local_tracks(self, play_from):
|
def create_local_tracks(self, play_from):
|
||||||
if play_from:
|
if play_from:
|
||||||
@@ -55,7 +53,6 @@ class StreamClient:
|
|||||||
else:
|
else:
|
||||||
if self.relay is None:
|
if self.relay is None:
|
||||||
self.relay = MediaRelay()
|
self.relay = MediaRelay()
|
||||||
print("Created local track from microphone stream")
|
|
||||||
return self.relay.subscribe(self.player.audio), None
|
return self.relay.subscribe(self.player.audio), None
|
||||||
|
|
||||||
def channel_log(self, channel, t, message):
|
def channel_log(self, channel, t, message):
|
||||||
|
|||||||
Reference in New Issue
Block a user