DailyTransport: fix audio/video renderers registration
This commit is contained in:
@@ -22,6 +22,7 @@ from daily import (
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from pipecat.audio.utils import create_default_resampler
|
||||||
from pipecat.audio.vad.vad_analyzer import VADAnalyzer, VADParams
|
from pipecat.audio.vad.vad_analyzer import VADAnalyzer, VADParams
|
||||||
from pipecat.frames.frames import (
|
from pipecat.frames.frames import (
|
||||||
CancelFrame,
|
CancelFrame,
|
||||||
@@ -334,6 +335,14 @@ class DailyTransportClient(EventHandler):
|
|||||||
def participant_id(self) -> str:
|
def participant_id(self) -> str:
|
||||||
return self._participant_id
|
return self._participant_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def in_sample_rate(self) -> int:
|
||||||
|
return self._in_sample_rate
|
||||||
|
|
||||||
|
@property
|
||||||
|
def out_sample_rate(self) -> int:
|
||||||
|
return self._out_sample_rate
|
||||||
|
|
||||||
async def send_message(self, frame: TransportMessageFrame | TransportMessageUrgentFrame):
|
async def send_message(self, frame: TransportMessageFrame | TransportMessageUrgentFrame):
|
||||||
if not self._joined:
|
if not self._joined:
|
||||||
return
|
return
|
||||||
@@ -665,9 +674,17 @@ class DailyTransportClient(EventHandler):
|
|||||||
self,
|
self,
|
||||||
participant_id: str,
|
participant_id: str,
|
||||||
callback: Callable,
|
callback: Callable,
|
||||||
audio_source: str = "camera",
|
audio_source: str = "microphone",
|
||||||
):
|
):
|
||||||
self._audio_renderers[participant_id][audio_source] = callback
|
# Only enable the desired audio source subscription on this participant.
|
||||||
|
if audio_source in ("microphone", "screenAudio"):
|
||||||
|
media = {"media": {audio_source: "subscribed"}}
|
||||||
|
else:
|
||||||
|
media = {"media": {"customAudio": {audio_source: "subscribed"}}}
|
||||||
|
|
||||||
|
await self.update_subscriptions(participant_settings={participant_id: media})
|
||||||
|
|
||||||
|
self._audio_renderers[participant_id] = {audio_source: callback}
|
||||||
|
|
||||||
self._client.set_audio_renderer(
|
self._client.set_audio_renderer(
|
||||||
participant_id,
|
participant_id,
|
||||||
@@ -683,12 +700,15 @@ class DailyTransportClient(EventHandler):
|
|||||||
video_source: str = "camera",
|
video_source: str = "camera",
|
||||||
color_format: str = "RGB",
|
color_format: str = "RGB",
|
||||||
):
|
):
|
||||||
# Only enable the desired video source subscription on this participant.
|
# Only enable the desired audio source subscription on this participant.
|
||||||
await self.update_subscriptions(
|
if video_source in ("camera", "screenVideo"):
|
||||||
participant_settings={participant_id: {"media": {video_source: "subscribed"}}}
|
media = {"media": {video_source: "subscribed"}}
|
||||||
)
|
else:
|
||||||
|
media = {"media": {"customVideo": {video_source: "subscribed"}}}
|
||||||
|
|
||||||
self._video_renderers[participant_id][video_source] = callback
|
await self.update_subscriptions(participant_settings={participant_id: media})
|
||||||
|
|
||||||
|
self._video_renderers[participant_id] = {video_source: callback}
|
||||||
|
|
||||||
self._client.set_video_renderer(
|
self._client.set_video_renderer(
|
||||||
participant_id,
|
participant_id,
|
||||||
@@ -886,6 +906,8 @@ class DailyInputTransport(BaseInputTransport):
|
|||||||
# internally to be processed.
|
# internally to be processed.
|
||||||
self._audio_in_task = None
|
self._audio_in_task = None
|
||||||
|
|
||||||
|
self._resampler = create_default_resampler()
|
||||||
|
|
||||||
self._vad_analyzer: Optional[VADAnalyzer] = params.vad_analyzer
|
self._vad_analyzer: Optional[VADAnalyzer] = params.vad_analyzer
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -978,10 +1000,14 @@ class DailyInputTransport(BaseInputTransport):
|
|||||||
async def _on_participant_audio_data(
|
async def _on_participant_audio_data(
|
||||||
self, participant_id: str, audio: AudioData, audio_source: str
|
self, participant_id: str, audio: AudioData, audio_source: str
|
||||||
):
|
):
|
||||||
|
resampled = await self._resampler.resample(
|
||||||
|
audio.audio_frames, audio.sample_rate, self._client.out_sample_rate
|
||||||
|
)
|
||||||
|
|
||||||
frame = UserAudioRawFrame(
|
frame = UserAudioRawFrame(
|
||||||
user_id=participant_id,
|
user_id=participant_id,
|
||||||
audio=audio.audio_frames,
|
audio=resampled,
|
||||||
sample_rate=audio.sample_rate,
|
sample_rate=self._client.out_sample_rate,
|
||||||
num_channels=audio.num_channels,
|
num_channels=audio.num_channels,
|
||||||
)
|
)
|
||||||
frame.source = audio_source
|
frame.source = audio_source
|
||||||
@@ -1004,10 +1030,12 @@ class DailyInputTransport(BaseInputTransport):
|
|||||||
video_source: str = "camera",
|
video_source: str = "camera",
|
||||||
color_format: str = "RGB",
|
color_format: str = "RGB",
|
||||||
):
|
):
|
||||||
self._video_renderers[participant_id][video_source] = {
|
self._video_renderers[participant_id] = {
|
||||||
"framerate": framerate,
|
video_source: {
|
||||||
"timestamp": 0,
|
"framerate": framerate,
|
||||||
"render_next_frame": [],
|
"timestamp": 0,
|
||||||
|
"render_next_frame": [],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await self._client.capture_participant_video(
|
await self._client.capture_participant_video(
|
||||||
|
|||||||
Reference in New Issue
Block a user