This commit is contained in:
yumoqing 2024-09-11 15:08:56 +08:00
parent 1382ecdba5
commit 8db51c5240
3 changed files with 13 additions and 6 deletions

View File

@ -12,11 +12,16 @@ class LLMAudioStreamTrack(AudioStreamTrack):
async def recv(self): async def recv(self):
print(f'LLMAudioStreamTrack():recv() called ....') print(f'LLMAudioStreamTrack():recv() called ....')
b = self.get_audio_bytes() try:
if b is None: b = self.get_audio_bytes()
return b if b is None:
frame = AudioFrame.from_ndarray(io.BytesIO(b), format='s16', layout='mono') return b
return frame frame = AudioFrame.from_ndarray(io.BytesIO(b), format='s16', layout='mono')
return frame
except Exception as e:
print_exc()
print(f'{self.__class__.__name__} recv() exception happened')
raise e
def set_cur_audio_iter(self): def set_cur_audio_iter(self):
if len(self.audio_iters) == 0: if len(self.audio_iters) == 0:

View File

@ -57,6 +57,7 @@ class MyAudioStreamTrack(AudioStreamTrack):
async def _recv(self): async def _recv(self):
if self.source is None: if self.source is None:
print('self._recv() return None')
return None return None
f = await self.track.recv() f = await self.track.recv()
return f return f

View File

@ -126,7 +126,8 @@ class RTCLLM:
'player':player, 'player':player,
'pc':pc 'pc':pc
}) })
pc.addTrack(MyAudioStreamTrack(player)) pc.addTrack(llmtrack)
# pc.addTrack(MyAudioStreamTrack(player))
pc.addTrack(MyVideoStreamTrack(player)) pc.addTrack(MyVideoStreamTrack(player))
# pc.addTrack(LoopingVideoTrack('./1.mp4')) # pc.addTrack(LoopingVideoTrack('./1.mp4'))
# pc.addTrack(player.video) # pc.addTrack(player.video)