From 8deeff588f05fe6d949e851aa380f9add2c488f9 Mon Sep 17 00:00:00 2001 From: Gokul Mohanarangan Date: Tue, 11 Jul 2023 12:41:26 +0530 Subject: [PATCH] clean up --- constants.py | 0 server_executor_cleaned.py | 17 +---------------- server_multithreaded.py | 16 +++------------- stream_client.py | 3 --- 4 files changed, 4 insertions(+), 32 deletions(-) create mode 100644 constants.py diff --git a/constants.py b/constants.py new file mode 100644 index 00000000..e69de29b diff --git a/server_executor_cleaned.py b/server_executor_cleaned.py index 1a40b4af..487bf0f8 100644 --- a/server_executor_cleaned.py +++ b/server_executor_cleaned.py @@ -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): diff --git a/server_multithreaded.py b/server_multithreaded.py index 5b1baf88..bf0c371d 100644 --- a/server_multithreaded.py +++ b/server_multithreaded.py @@ -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) diff --git a/stream_client.py b/stream_client.py index bd0eb159..22177970 100644 --- a/stream_client.py +++ b/stream_client.py @@ -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):