Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ GROQ_API_KEY=...

# Heygen
HEYGEN_API_KEY=...
HEYGEN_LIVE_AVATAR_API_KEY=...

# Hume
HUME_API_KEY=...
Expand Down
8 changes: 3 additions & 5 deletions examples/foundational/43a-heygen-video-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pipecat.services.cartesia.tts import CartesiaTTSService
from pipecat.services.deepgram.stt import DeepgramSTTService
from pipecat.services.google.llm import GoogleLLMService
from pipecat.services.heygen.api import AvatarQuality, NewSessionRequest
from pipecat.services.heygen.client import ServiceType
from pipecat.services.heygen.video import HeyGenVideoService
from pipecat.transports.base_transport import BaseTransport, TransportParams
from pipecat.transports.daily.transport import DailyParams, DailyTransport
Expand Down Expand Up @@ -73,11 +73,9 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
llm = GoogleLLMService(api_key=os.getenv("GOOGLE_API_KEY"))

heyGen = HeyGenVideoService(
api_key=os.getenv("HEYGEN_API_KEY"),
api_key=os.getenv("HEYGEN_LIVE_AVATAR_API_KEY"),
service_type=ServiceType.LIVE_AVATAR,
session=session,
session_request=NewSessionRequest(
avatar_id="Shawn_Therapist_public", version="v2", quality=AvatarQuality.high
),
)

messages = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from loguru import logger
from pydantic import BaseModel, Field

from pipecat.services.heygen.base_api import BaseAvatarApi, StandardSessionResponse


class AvatarQuality(str, Enum):
"""Enum representing different avatar quality levels."""
Expand Down Expand Up @@ -136,7 +138,7 @@ def __init__(self, message: str, status: int, response_text: str) -> None:
self.response_text = response_text


class HeyGenApi:
class HeyGenApi(BaseAvatarApi):
"""HeyGen Streaming API client."""

BASE_URL = "https://api.heygen.com/v1"
Expand Down Expand Up @@ -193,16 +195,16 @@ async def _request(self, path: str, params: Dict[str, Any], expect_data: bool =
logger.error(f"Network error while calling HeyGen API: {str(e)}")
raise

async def new_session(self, request_data: NewSessionRequest) -> HeyGenSession:
"""Create a new streaming session.
async def new_session(self, request_data: NewSessionRequest) -> StandardSessionResponse:
"""Create a new streaming session and start it immediately.

https://docs.heygen.com/reference/new-session

Args:
request_data: Session configuration parameters.

Returns:
Session information, including ID and access token.
StandardSessionResponse: Standardized session information with HeyGen raw response.
"""
params = {
"quality": request_data.quality,
Expand All @@ -225,9 +227,21 @@ async def new_session(self, request_data: NewSessionRequest) -> HeyGenSession:
session_info = await self._request("/streaming.new", params)
print("heygen session info", session_info)

return HeyGenSession.model_validate(session_info)
heygen_session = HeyGenSession.model_validate(session_info)

await self._start_session(heygen_session.session_id)

# Convert to standardized response
return StandardSessionResponse(
session_id=heygen_session.session_id,
access_token=heygen_session.access_token,
livekit_url=heygen_session.url,
livekit_agent_token=heygen_session.livekit_agent_token,
ws_url=heygen_session.realtime_endpoint,
raw_response=heygen_session,
)

async def start_session(self, session_id: str) -> Any:
async def _start_session(self, session_id: str) -> Any:
"""Start the streaming session.

https://docs.heygen.com/reference/start-session
Expand Down
Loading
Loading