From 6e151f939991b7e9870c692c228169906463da7b Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 4 Sep 2024 11:00:07 +0800 Subject: [PATCH] bugfix --- rtcllm/rtc.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rtcllm/rtc.py b/rtcllm/rtc.py index b9a5b10..737107e 100644 --- a/rtcllm/rtc.py +++ b/rtcllm/rtc.py @@ -21,6 +21,17 @@ from aav import MyAudioTrack, MyVideoTrack videos = ['./1.mp4', './2.mp4'] +async def pc_get_local_candidates(pc, peer): + await pc.__gather() + if not peer.l_candidates: + peer.l_candidates = [] + for c in pc.__iceTransports.local_candidates(): + if c not in peer.l_candidates: + peer.l_candidates.append(c) + pc.emit('icecandidate', c) + +RTCPeerConnection.get_local_candidates = pc_get_local_candidates + class RTCLLM: def __init__(self, ws_url, iceServers): self.stt_model = WhisperModel('large-v3', device="cuda", compute_type="float16") @@ -152,6 +163,7 @@ class RTCLLM: async def response_offer(self, data): pc = self.get_pc(data) + peer = self.peers[data['from'].id] if pc is None: print(f'{self.peers=}, {data=}') return @@ -169,7 +181,7 @@ class RTCLLM: 'answer':{'type':pc.localDescription.type, 'sdp':pc.localDescription.sdp}, 'to':data['from'] })) - cands = await pc.gather_candidates() + cands = await pc.get_local_candidates(peer) for c in cands: await self.send_candidate(data['from'], c)