reformatting

This commit is contained in:
Gokul Mohanarangan
2023-07-11 13:45:28 +05:30
parent 54de3683b3
commit 88af112131
7 changed files with 27 additions and 27 deletions

View File

@@ -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)

View File

@@ -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}
),
)

View File

@@ -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()

View File

@@ -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())

View File

@@ -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)):

View File

@@ -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)

View File

@@ -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']