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