transports: add support for sending transport messages
This commit is contained in:
@@ -21,7 +21,8 @@ from pipecat.frames.frames import (
|
|||||||
StartFrame,
|
StartFrame,
|
||||||
EndFrame,
|
EndFrame,
|
||||||
Frame,
|
Frame,
|
||||||
ImageRawFrame)
|
ImageRawFrame,
|
||||||
|
TransportMessageFrame)
|
||||||
from pipecat.transports.base_transport import TransportParams
|
from pipecat.transports.base_transport import TransportParams
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
@@ -60,6 +61,9 @@ class BaseOutputTransport(FrameProcessor):
|
|||||||
|
|
||||||
self._stopped_event.set()
|
self._stopped_event.set()
|
||||||
|
|
||||||
|
def send_message(self, frame: TransportMessageFrame):
|
||||||
|
pass
|
||||||
|
|
||||||
def write_frame_to_camera(self, frame: ImageRawFrame):
|
def write_frame_to_camera(self, frame: ImageRawFrame):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -98,6 +102,7 @@ class BaseOutputTransport(FrameProcessor):
|
|||||||
return (isinstance(frame, AudioRawFrame)
|
return (isinstance(frame, AudioRawFrame)
|
||||||
or isinstance(frame, ImageRawFrame)
|
or isinstance(frame, ImageRawFrame)
|
||||||
or isinstance(frame, SpriteFrame)
|
or isinstance(frame, SpriteFrame)
|
||||||
|
or isinstance(frame, TransportMessageFrame)
|
||||||
or isinstance(frame, CancelFrame)
|
or isinstance(frame, CancelFrame)
|
||||||
or isinstance(frame, EndFrame))
|
or isinstance(frame, EndFrame))
|
||||||
|
|
||||||
@@ -121,6 +126,8 @@ class BaseOutputTransport(FrameProcessor):
|
|||||||
self._set_camera_image(frame)
|
self._set_camera_image(frame)
|
||||||
elif isinstance(frame, SpriteFrame) and self._params.camera_out_enabled:
|
elif isinstance(frame, SpriteFrame) and self._params.camera_out_enabled:
|
||||||
self._set_camera_images(frame.images)
|
self._set_camera_images(frame.images)
|
||||||
|
elif isinstance(frame, TransportMessageFrame):
|
||||||
|
self.send_message(frame)
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import threading
|
|||||||
import time
|
import time
|
||||||
import types
|
import types
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Any, Callable, Mapping
|
from typing import Any, Callable, Mapping
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ from pipecat.frames.frames import (
|
|||||||
InterimTranscriptionFrame,
|
InterimTranscriptionFrame,
|
||||||
SpriteFrame,
|
SpriteFrame,
|
||||||
TranscriptionFrame,
|
TranscriptionFrame,
|
||||||
|
TransportMessageFrame,
|
||||||
UserImageRawFrame,
|
UserImageRawFrame,
|
||||||
UserImageRequestFrame)
|
UserImageRequestFrame)
|
||||||
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
||||||
@@ -51,6 +53,11 @@ except ModuleNotFoundError as e:
|
|||||||
VAD_RESET_PERIOD_MS = 2000
|
VAD_RESET_PERIOD_MS = 2000
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class DailyTransportMessageFrame(TransportMessageFrame):
|
||||||
|
participant_id: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class WebRTCVADAnalyzer(VADAnalyzer):
|
class WebRTCVADAnalyzer(VADAnalyzer):
|
||||||
|
|
||||||
def __init__(self, sample_rate=16000, num_channels=1):
|
def __init__(self, sample_rate=16000, num_channels=1):
|
||||||
@@ -169,6 +176,9 @@ class DailySession(EventHandler):
|
|||||||
state = self._vad_analyzer.analyze_audio(audio_frames)
|
state = self._vad_analyzer.analyze_audio(audio_frames)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
def send_message(self, frame: DailyTransportMessageFrame):
|
||||||
|
self._client.send_app_message(frame.message, frame.participant_id)
|
||||||
|
|
||||||
def read_raw_audio_frames(self, frame_count: int) -> bytes:
|
def read_raw_audio_frames(self, frame_count: int) -> bytes:
|
||||||
return self._speaker.read_frames(frame_count)
|
return self._speaker.read_frames(frame_count)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user