mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-16 08:25:18 +02:00
feat: added vobiz telephony (#65)
* feat: added vobiz telephony * chore: run formatter * chore: add migration * Add tsclient --------- Co-authored-by: Abhishek Kumar <abhishek@a6k.me>
This commit is contained in:
parent
749a0c557f
commit
09897cb5d8
16 changed files with 994 additions and 19 deletions
|
|
@ -85,7 +85,12 @@ def create_audio_config(transport_type: str) -> AudioConfig:
|
|||
Returns:
|
||||
AudioConfig instance with appropriate settings
|
||||
"""
|
||||
if transport_type in (WorkflowRunMode.STASIS.value, WorkflowRunMode.TWILIO.value):
|
||||
if transport_type in (
|
||||
WorkflowRunMode.STASIS.value,
|
||||
WorkflowRunMode.TWILIO.value,
|
||||
WorkflowRunMode.VOBIZ.value,
|
||||
):
|
||||
# Twilio, Vobiz, and Stasis use MULAW at 8kHz
|
||||
return AudioConfig(
|
||||
transport_in_sample_rate=8000,
|
||||
transport_out_sample_rate=8000,
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ from api.services.pipecat.tracing_config import setup_pipeline_tracing
|
|||
from api.services.pipecat.transport_setup import (
|
||||
create_stasis_transport,
|
||||
create_twilio_transport,
|
||||
create_vobiz_transport,
|
||||
create_vonage_transport,
|
||||
create_webrtc_transport,
|
||||
)
|
||||
|
|
@ -174,6 +175,70 @@ async def run_pipeline_vonage(
|
|||
raise
|
||||
|
||||
|
||||
async def run_pipeline_vobiz(
|
||||
websocket_client: WebSocket,
|
||||
stream_id: str,
|
||||
call_id: str,
|
||||
workflow_id: int,
|
||||
workflow_run_id: int,
|
||||
user_id: int,
|
||||
) -> None:
|
||||
"""Run pipeline for Vobiz using Plivo-compatible WebSocket protocol."""
|
||||
logger.info(
|
||||
f"[run {workflow_run_id}] Starting Vobiz pipeline - "
|
||||
f"stream_id={stream_id}, call_id={call_id}, workflow_id={workflow_id}"
|
||||
)
|
||||
set_current_run_id(workflow_run_id)
|
||||
|
||||
cost_info = {"call_id": call_id}
|
||||
await db_client.update_workflow_run(workflow_run_id, cost_info=cost_info)
|
||||
|
||||
workflow = await db_client.get_workflow(workflow_id, user_id)
|
||||
vad_config = None
|
||||
ambient_noise_config = None
|
||||
if workflow and workflow.workflow_configurations:
|
||||
if "vad_configuration" in workflow.workflow_configurations:
|
||||
vad_config = workflow.workflow_configurations["vad_configuration"]
|
||||
if "ambient_noise_configuration" in workflow.workflow_configurations:
|
||||
ambient_noise_config = workflow.workflow_configurations[
|
||||
"ambient_noise_configuration"
|
||||
]
|
||||
|
||||
try:
|
||||
audio_config = create_audio_config(WorkflowRunMode.VOBIZ.value)
|
||||
logger.info(
|
||||
f"[run {workflow_run_id}] Vobiz audio config: "
|
||||
f"sample_rate={audio_config.transport_in_sample_rate}Hz, format=MULAW"
|
||||
)
|
||||
|
||||
transport = await create_vobiz_transport(
|
||||
websocket_client,
|
||||
stream_id,
|
||||
call_id,
|
||||
workflow_run_id,
|
||||
audio_config,
|
||||
workflow.organization_id,
|
||||
vad_config,
|
||||
ambient_noise_config,
|
||||
)
|
||||
|
||||
logger.info(f"[run {workflow_run_id}] Starting Vobiz pipeline execution")
|
||||
await _run_pipeline(
|
||||
transport,
|
||||
workflow_id,
|
||||
workflow_run_id,
|
||||
user_id,
|
||||
audio_config=audio_config,
|
||||
)
|
||||
logger.info(f"[run {workflow_run_id}] Vobiz pipeline completed successfully")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"[run {workflow_run_id}] Error in Vobiz pipeline: {e}", exc_info=True
|
||||
)
|
||||
raise
|
||||
|
||||
|
||||
async def run_pipeline_smallwebrtc(
|
||||
webrtc_connection: SmallWebRTCConnection,
|
||||
workflow_id: int,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from pipecat.audio.mixers.silence_mixer import SilenceAudioMixer
|
|||
from pipecat.audio.mixers.soundfile_mixer import SoundfileMixer
|
||||
from pipecat.audio.turn.smart_turn.base_smart_turn import SmartTurnParams
|
||||
from pipecat.audio.vad.silero import SileroVADAnalyzer, VADParams
|
||||
from pipecat.serializers.plivo import PlivoFrameSerializer
|
||||
from pipecat.serializers.twilio import TwilioFrameSerializer
|
||||
from pipecat.serializers.vonage import VonageFrameSerializer
|
||||
from pipecat.transports.base_transport import TransportParams
|
||||
|
|
@ -233,6 +234,117 @@ async def create_vonage_transport(
|
|||
)
|
||||
|
||||
|
||||
async def create_vobiz_transport(
|
||||
websocket_client: WebSocket,
|
||||
stream_id: str,
|
||||
call_id: str,
|
||||
workflow_run_id: int,
|
||||
audio_config: AudioConfig,
|
||||
organization_id: int,
|
||||
vad_config: dict | None = None,
|
||||
ambient_noise_config: dict | None = None,
|
||||
):
|
||||
"""Create a transport for Vobiz connections.
|
||||
|
||||
Vobiz uses Plivo-compatible WebSocket protocol:
|
||||
- MULAW audio at 8kHz (same as Twilio)
|
||||
- Base64-encoded audio in JSON messages
|
||||
- PlivoFrameSerializer handles the protocol
|
||||
"""
|
||||
from loguru import logger
|
||||
|
||||
logger.info(
|
||||
f"[run {workflow_run_id}] Creating Vobiz transport - "
|
||||
f"stream_id={stream_id}, call_id={call_id}"
|
||||
)
|
||||
|
||||
# Load Vobiz configuration from database
|
||||
from api.services.telephony.factory import load_telephony_config
|
||||
|
||||
config = await load_telephony_config(organization_id)
|
||||
|
||||
if config.get("provider") != "vobiz":
|
||||
raise ValueError(f"Expected Vobiz provider, got {config.get('provider')}")
|
||||
|
||||
auth_id = config.get("auth_id")
|
||||
auth_token = config.get("auth_token")
|
||||
|
||||
if not auth_id or not auth_token:
|
||||
raise ValueError(
|
||||
f"Incomplete Vobiz configuration for organization {organization_id}"
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
f"[run {workflow_run_id}] Vobiz config loaded - auth_id={auth_id}, "
|
||||
f"from_numbers={len(config.get('from_numbers', []))} numbers"
|
||||
)
|
||||
|
||||
turn_analyzer = create_turn_analyzer(workflow_run_id, audio_config)
|
||||
|
||||
# Use PlivoFrameSerializer for Vobiz (Plivo-compatible protocol)
|
||||
serializer = PlivoFrameSerializer(
|
||||
stream_id=stream_id,
|
||||
call_id=call_id,
|
||||
auth_id=auth_id,
|
||||
auth_token=auth_token,
|
||||
params=PlivoFrameSerializer.InputParams(
|
||||
plivo_sample_rate=8000, # Vobiz uses MULAW at 8kHz
|
||||
sample_rate=audio_config.pipeline_sample_rate,
|
||||
),
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
f"[run {workflow_run_id}] PlivoFrameSerializer created for Vobiz - "
|
||||
f"transport_rate=8000Hz, pipeline_rate={audio_config.pipeline_sample_rate}Hz"
|
||||
)
|
||||
|
||||
# Create WebSocket transport (same structure as Twilio/Vonage)
|
||||
transport = FastAPIWebsocketTransport(
|
||||
websocket=websocket_client,
|
||||
params=FastAPIWebsocketParams(
|
||||
audio_in_enabled=True,
|
||||
audio_out_enabled=True,
|
||||
audio_in_sample_rate=audio_config.transport_in_sample_rate,
|
||||
audio_out_sample_rate=audio_config.transport_out_sample_rate,
|
||||
vad_analyzer=(
|
||||
SileroVADAnalyzer(
|
||||
params=VADParams(
|
||||
confidence=vad_config.get("confidence", 0.7),
|
||||
start_secs=vad_config.get("start_seconds", 0.4),
|
||||
stop_secs=vad_config.get("stop_seconds", 0.8),
|
||||
min_volume=vad_config.get("minimum_volume", 0.6),
|
||||
)
|
||||
)
|
||||
if vad_config
|
||||
else SileroVADAnalyzer()
|
||||
),
|
||||
audio_out_mixer=(
|
||||
SoundfileMixer(
|
||||
sound_files={
|
||||
"office": APP_ROOT_DIR
|
||||
/ "assets"
|
||||
/ f"office-ambience-{audio_config.transport_out_sample_rate}-mono.wav"
|
||||
},
|
||||
default_sound="office",
|
||||
volume=ambient_noise_config.get("volume", 0.3),
|
||||
)
|
||||
if ambient_noise_config and ambient_noise_config.get("enabled", False)
|
||||
else SilenceAudioMixer()
|
||||
),
|
||||
turn_analyzer=turn_analyzer,
|
||||
serializer=serializer,
|
||||
audio_in_filter=RNNoiseFilter(library_path=librnnoise_path)
|
||||
if ENABLE_RNNOISE
|
||||
else None,
|
||||
),
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"[run {workflow_run_id}] Vobiz transport created successfully (VAD enabled)"
|
||||
)
|
||||
return transport
|
||||
|
||||
|
||||
def create_webrtc_transport(
|
||||
webrtc_connection: SmallWebRTCConnection,
|
||||
workflow_run_id: int,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue