This commit is contained in:
yumoqing 2024-09-11 15:51:19 +08:00
parent c05f9d7c89
commit 5a6d421b3d
2 changed files with 11 additions and 3 deletions

View File

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

View File

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