diff --git a/client.py b/client.py index d6393712..5cf8d47d 100644 --- a/client.py +++ b/client.py @@ -64,7 +64,6 @@ async def main(): ping_pong=args.ping_pong ) await sc.start() - print("Stream client started") async for msg in sc.get_reader(): print(msg) diff --git a/server_executor_cleaned.py b/server_executor_cleaned.py index b9334e52..ecac6d48 100644 --- a/server_executor_cleaned.py +++ b/server_executor_cleaned.py @@ -126,7 +126,7 @@ async def offer(request): return web.Response( content_type="application/json", text=json.dumps( - { "sdp": pc.localDescription.sdp, "type": pc.localDescription.type } + {"sdp": pc.localDescription.sdp, "type": pc.localDescription.type} ), ) diff --git a/server_multithreaded.py b/server_multithreaded.py index b62def09..7382a654 100644 --- a/server_multithreaded.py +++ b/server_multithreaded.py @@ -8,6 +8,7 @@ import wave from concurrent.futures import ThreadPoolExecutor import jax.numpy as jnp +import requests from aiohttp import web from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription from aiortc.contrib.media import MediaRelay @@ -77,10 +78,11 @@ def get_transcription(): wf.close() whisper_result = pipeline(out_file.getvalue()) - item = { 'text': whisper_result["text"], - 'start_time': str(frames[0].time), - 'time': str(datetime.datetime.now()) - } + item = { + 'text': whisper_result["text"], + 'start_time': str(frames[0].time), + 'time': str(datetime.datetime.now()) + } sorted_message_queue[frames[0].time] = str(item) start_messaging_thread() except Exception as e: @@ -89,7 +91,7 @@ def get_transcription(): class AudioStreamTrack(MediaStreamTrack): """ - A video stream track that transforms frames from an another track. + An audio stream track to send audio frames. """ kind = "audio" @@ -109,15 +111,13 @@ def start_messaging_thread(): message_thread.start() -def start_transcription_thread(max_threads): - t_threads = [] +def start_transcription_thread(max_threads: int): for i in range(max_threads): t_thread = threading.Thread(target=get_transcription, args=(i,)) - t_threads.append(t_thread) t_thread.start() -async def offer(request): +async def offer(request: requests.Request): params = await request.json() offer = RTCSessionDescription(sdp=params["sdp"], type=params["type"]) @@ -125,7 +125,7 @@ async def offer(request): pc_id = "PeerConnection(%s)" % uuid.uuid4() pcs.add(pc) - def log_info(msg, *args): + def log_info(msg: str, *args): logger.info(pc_id + " " + msg, *args) log_info("Created for %s", request.remote) @@ -138,7 +138,7 @@ async def offer(request): start_time = datetime.datetime.now() @channel.on("message") - def on_message(message): + def on_message(message: str): channel_log(channel, "<", message) if isinstance(message, str) and message.startswith("ping"): # reply @@ -164,13 +164,14 @@ async def offer(request): await pc.setLocalDescription(answer) return web.Response( content_type="application/json", - text=json.dumps( - { "sdp": pc.localDescription.sdp, "type": pc.localDescription.type } - ), + text=json.dumps({ + "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] await asyncio.gather(*coros) pcs.clear() diff --git a/stream_client.py b/stream_client.py index a6b879e2..d7791e5c 100644 --- a/stream_client.py +++ b/stream_client.py @@ -38,7 +38,7 @@ class StreamClient: self.time_start = None self.queue = asyncio.Queue() self.player = MediaPlayer(':' + str(config['DEFAULT']["AV_FOUNDATION_DEVICE_ID"]), - format='avfoundation', options={ 'channels': '2' }) + format='avfoundation', options={'channels': '2'}) def stop(self): self.loop.run_until_complete(self.signaling.close()) diff --git a/utils/text_utilities.py b/utils/text_utilities.py index f41cd800..900f9194 100644 --- a/utils/text_utilities.py +++ b/utils/text_utilities.py @@ -70,7 +70,7 @@ def remove_whisper_repetitive_hallucination(nonduplicate_sentences): for sent in nonduplicate_sentences: temp_result = "" - seen = { } + seen = {} words = nltk.word_tokenize(sent) n_gram_filter = 3 for i in range(len(words)): diff --git a/utils/viz_utilities.py b/utils/viz_utilities.py index 77aa556f..fa09144e 100644 --- a/utils/viz_utilities.py +++ b/utils/viz_utilities.py @@ -88,11 +88,11 @@ def create_talk_diff_scatter_viz(timestamp, real_time=False): # create df for processing df = pd.DataFrame.from_dict(res["chunks"]) - covered_items = { } + covered_items = {} # ts: timestamp # Map each timestamped chunk with top1 and top2 matched agenda - ts_to_topic_mapping_top_1 = { } - ts_to_topic_mapping_top_2 = { } + ts_to_topic_mapping_top_1 = {} + ts_to_topic_mapping_top_2 = {} # Also create a mapping of the different timestamps in which each topic was covered topic_to_ts_mapping_top_1 = collections.defaultdict(list) diff --git a/whisjax_realtime.py b/whisjax_realtime.py index d8623ddc..68dc472a 100644 --- a/whisjax_realtime.py +++ b/whisjax_realtime.py @@ -57,7 +57,7 @@ def main(): global proceed proceed = False - transcript_with_timestamp = { "text": "", "chunks": [] } + transcript_with_timestamp = {"text": "", "chunks": []} last_transcribed_time = 0.0 listener = keyboard.Listener(on_press=on_press) @@ -87,10 +87,10 @@ def main(): if end is None: end = start + 15.0 duration = end - start - item = { 'timestamp': (last_transcribed_time, last_transcribed_time + duration), - 'text': whisper_result['text'], - 'stats': (str(end_time - start_time), str(duration)) - } + item = {'timestamp': (last_transcribed_time, last_transcribed_time + duration), + 'text': whisper_result['text'], + 'stats': (str(end_time - start_time), str(duration)) + } last_transcribed_time = last_transcribed_time + duration transcript_with_timestamp["chunks"].append(item) transcription += whisper_result['text']