Merge pull request #170 from pipecat-ai/add-daily-transport-dialout-support

transport(daily): add dialout support
This commit is contained in:
Aleix Conchillo Flaqué
2024-05-24 04:19:51 +08:00
committed by GitHub
3 changed files with 94 additions and 20 deletions

View File

@@ -5,6 +5,17 @@ All notable changes to **pipecat** will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Added Daily transport `start_dialout()` to be able to make phone or SIP calls.
See https://reference-python.daily.co/api_reference.html#daily.CallClient.start_dialout
- Added Daily transport events: `on_dialin_ready`, `on_dialout_connected`,
`on_dialout_stopped`, `on_dialout_error` and `on_dialout_warning`.
See https://reference-python.daily.co/api_reference.html#daily.EventHandler
## [0.0.21] - 2024-05-22
### Added

View File

@@ -35,7 +35,7 @@ Website = "https://pipecat.ai"
[project.optional-dependencies]
anthropic = [ "anthropic~=0.25.7" ]
azure = [ "azure-cognitiveservices-speech~=1.37.0" ]
daily = [ "daily-python~=0.7.4" ]
daily = [ "daily-python~=0.8.0" ]
examples = [ "python-dotenv~=1.0.0", "flask~=3.0.3", "flask_cors~=4.0.1" ]
fal = [ "fal-client~=0.4.0" ]
google = [ "google-generativeai~=0.5.3" ]

View File

@@ -103,11 +103,16 @@ class DailyParams(TransportParams):
class DailyCallbacks(BaseModel):
on_joined: Callable[[Mapping[str, Any]], None]
on_left: Callable[[], None]
on_error: Callable[[str], None]
on_app_message: Callable[[Any, str], None]
on_dialin_ready: Callable[[str], None]
on_dialout_connected: Callable[[Any], None]
on_dialout_stopped: Callable[[Any], None]
on_dialout_error: Callable[[Any], None]
on_dialout_warning: Callable[[Any], None]
on_first_participant_joined: Callable[[Mapping[str, Any]], None]
on_participant_joined: Callable[[Mapping[str, Any]], None]
on_participant_left: Callable[[Mapping[str, Any], str], None]
on_first_participant_joined: Callable[[Mapping[str, Any]], None]
on_app_message: Callable[[Any, str], None]
on_error: Callable[[str], None]
class DailyTransportClient(EventHandler):
@@ -328,6 +333,9 @@ class DailyTransportClient(EventHandler):
self._client.release()
self._client = None
def start_dialout(self, settings):
self._client.start_dialout(settings)
def capture_participant_transcription(self, participant_id: str, callback: Callable):
if not self._params.transcription_enabled:
return
@@ -361,6 +369,24 @@ class DailyTransportClient(EventHandler):
# Daily (EventHandler)
#
def on_app_message(self, message: Any, sender: str):
self._callbacks.on_app_message(message, sender)
def on_dialin_ready(self, sip_endpoint: str):
self._callbacks.on_dialin_ready(sip_endpoint)
def on_dialout_connected(self, data: Any):
self._callbacks.on_dialout_connected(data)
def on_dialout_stopped(self, data: Any):
self._callbacks.on_dialout_stopped(data)
def on_dialout_error(self, data: Any):
self._callbacks.on_dialout_error(data)
def on_dialout_warning(self, data: Any):
self._callbacks.on_dialout_warning(data)
def on_participant_joined(self, participant):
id = participant["id"]
logger.info(f"Participant joined {id}")
@@ -395,9 +421,6 @@ class DailyTransportClient(EventHandler):
def on_transcription_stopped(self, stopped_by, stopped_by_error):
logger.debug("Transcription stopped")
def on_app_message(self, message: Any, sender: str):
self._callbacks.on_app_message(message, sender)
#
# Daily (CallClient callbacks)
#
@@ -601,11 +624,16 @@ class DailyTransport(BaseTransport):
callbacks = DailyCallbacks(
on_joined=self._on_joined,
on_left=self._on_left,
on_error=self._on_error,
on_app_message=self._on_app_message,
on_dialin_ready=self._on_dialin_ready,
on_dialout_connected=self._on_dialout_connected,
on_dialout_stopped=self._on_dialout_stopped,
on_dialout_error=self._on_dialout_error,
on_dialout_warning=self._on_dialout_warning,
on_first_participant_joined=self._on_first_participant_joined,
on_participant_joined=self._on_participant_joined,
on_participant_left=self._on_participant_left,
on_app_message=self._on_app_message,
on_error=self._on_error,
)
self._params = params
@@ -620,9 +648,14 @@ class DailyTransport(BaseTransport):
# these handlers.
self._register_event_handler("on_joined")
self._register_event_handler("on_left")
self._register_event_handler("on_dialin_ready")
self._register_event_handler("on_dialout_connected")
self._register_event_handler("on_dialout_stopped")
self._register_event_handler("on_dialout_error")
self._register_event_handler("on_dialout_warning")
self._register_event_handler("on_first_participant_joined")
self._register_event_handler("on_participant_joined")
self._register_event_handler("on_participant_left")
self._register_event_handler("on_first_participant_joined")
#
# BaseTransport
@@ -654,6 +687,9 @@ class DailyTransport(BaseTransport):
if self._output:
await self._output.process_frame(frame, FrameDirection.DOWNSTREAM)
def start_dialout(self, settings):
self._client.start_dialout(settings)
def capture_participant_transcription(self, participant_id: str):
self._client.capture_participant_transcription(
participant_id,
@@ -681,6 +717,25 @@ class DailyTransport(BaseTransport):
# the client should report the error.
pass
def _on_app_message(self, message: Any, sender: str):
if self._input:
self._input.push_app_message(message, sender)
def _on_dialin_ready(self, sip_endpoint):
self.on_dialin_ready(sip_endpoint)
def _on_dialout_connected(self, data):
self.on_dialout_connected(data)
def _on_dialout_stopped(self, data):
self.on_dialout_stopped(data)
def _on_dialout_error(self, data):
self.on_dialout_error(data)
def _on_dialout_warning(self, data):
self.on_dialout_warning(data)
def _on_participant_joined(self, participant):
self.on_participant_joined(participant)
@@ -690,10 +745,6 @@ class DailyTransport(BaseTransport):
def _on_first_participant_joined(self, participant):
self.on_first_participant_joined(participant)
def _on_app_message(self, message: Any, sender: str):
if self._input:
self._input.push_app_message(message, sender)
def _on_transcription_message(self, participant_id, message):
text = message["text"]
timestamp = message["timestamp"]
@@ -717,15 +768,30 @@ class DailyTransport(BaseTransport):
def on_left(self):
pass
def on_dialin_ready(self, sip_endpoint):
pass
def on_dialout_connected(self, data):
pass
def on_dialout_stopped(self, data):
pass
def on_dialout_error(self, data):
pass
def on_dialout_warning(self, data):
pass
def on_first_participant_joined(self, participant):
pass
def on_participant_joined(self, participant):
pass
def on_participant_left(self, participant, reason):
pass
def on_first_participant_joined(self, participant):
pass
def event_handler(self, event_name: str):
def decorator(handler):
self._add_event_handler(event_name, handler)
@@ -765,8 +831,5 @@ class DailyTransport(BaseTransport):
logger.error(f"Exception in event handler {event_name}: {e}")
raise e
# def dialout(self, number):
# self.client.start_dialout({"phoneNumber": number})
# def start_recording(self):
# self.client.start_recording()