This commit is contained in:
yumoqing 2024-09-11 13:56:11 +08:00
parent c3799eda8c
commit 5040c0713b
2 changed files with 21 additions and 4 deletions

View File

@ -37,7 +37,7 @@ class MyTrackBase:
class MyAudioStreamTrack(AudioStreamTrack):
def __init__(self, source=None):
AudioStreamTrack.__init__(self)
super().__init__()
self.source = source
self.set_source_track()
print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}')
@ -67,7 +67,7 @@ class MyAudioStreamTrack(AudioStreamTrack):
class MyVideoStreamTrack(VideoStreamTrack):
def __init__(self, source=None):
VideoStreamTrack.__init__(self)
super().__init__()
self.source = source
self.set_source_track()
print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}')
@ -95,3 +95,19 @@ class MyVideoStreamTrack(VideoStreamTrack):
self.source = source
self.set_source_track()
class LoopingVideoTrack(VideoStreamTrack):
"""
A video track that loops a video file.
"""
def __init__(self, filename):
super().__init__()
self.player = MediaPlayer(filename)
self.iteration = 0
async def recv(self):
if self.player.video.readyState != 'live':
self.player = MediaPlayer(self.player._file_path)
frame = await self.player.video.recv()
return frame

View File

@ -22,7 +22,7 @@ import websockets
from stt import asr
from vad import AudioTrackVad
from a2a import LLMAudioStreamTrack
from aav import MyMediaPlayer, MyAudioStreamTrack, MyVideoStreamTrack
from aav import MyMediaPlayer, MyAudioStreamTrack, MyVideoStreamTrack, LoopingVideoTrack
from mini_omni.inference import OmniInference
@ -127,7 +127,8 @@ class RTCLLM:
'pc':pc
})
pc.addTrack(MyAudioStreamTrack(player))
pc.addTrack(MyVideoStreamTrack(player))
pc.addTrack(LoopingVideoTrack('./1.mp4'))
# pc.addTrack(MyVideoStreamTrack(player))
# pc.addTrack(player.video)
await self.ws_send(json.dumps({'type':'callAccepted', 'to':data['from']}))