diff --git a/rtcllm/a2a.py b/rtcllm/a2a.py index d44f0ec..3d7957d 100644 --- a/rtcllm/a2a.py +++ b/rtcllm/a2a.py @@ -1,3 +1,4 @@ +import os from traceback import print_exc import io import asyncio @@ -11,13 +12,12 @@ class LLMAudioStreamTrack(AudioStreamTrack): self.oi = omni_infer self.audio_iters = [] self.cur_iters = None + self.tmp_files = [] async def recv(self): - print(f'LLMAudioStreamTrack():recv() called ....') try: b = self.get_audio_bytes() if b is None: - print('LLMAudioStreamTrack return None ...') return await super().recv() frame = AudioFrame.from_ndarray(io.BytesIO(b), format='s16', layout='mono') print('LLMAudioStreamTrack return frame ...') @@ -43,9 +43,17 @@ class LLMAudioStreamTrack(AudioStreamTrack): return b except StopIteration: self.cur_iters = None + if len(self.tmp_files) > 0: + tf = self.tmp_files[0] + self.tmp_files.remove(tf) + os.remove(tf) return self.get_audio_bytes() def _feed(self, audio_file): + self.tmp_files.append(audio_file) + if audio_file is None: + print(f'*****{self.__class__.__name__}._feed(),{audio_file=}') + return x = self.oi.run_AT_batch_stream(audio_file) self.audio_iters.append(x) return x diff --git a/rtcllm/rtc.py b/rtcllm/rtc.py index 4e1035a..685c3ee 100644 --- a/rtcllm/rtc.py +++ b/rtcllm/rtc.py @@ -113,7 +113,7 @@ class RTCLLM: feed = awaitify(peer.llmtrack._feed) ret = await feed(audio) print(f'self.feed("{audio}") return {ret}') - os.remove(audio) + # os.remove(audio) async def auto_accept_call(self, data): opts = DictObject(iceServers=self.iceServers)