bithuman

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package bithuman provides bitHuman avatar integration for omni-livekit voice agents.

bitHuman is a real-time avatar animation platform that creates digital avatars with lip-sync to audio at 25 FPS. It supports both realistic humans and animated characters, and can run on CPU without requiring a GPU.

Quick Start

Create a bitHuman avatar session:

session, err := bithuman.NewSession(bithuman.SessionConfig{
	APIKey:  os.Getenv("BITHUMAN_API_KEY"),
	AgentID: "your-agent-id",
})
if err != nil {
	return err
}

err = session.Start(ctx, avatar.StartOptions{
	Room:             room,
	AgentIdentity:    "agent-123",
	LiveKitURL:       "wss://your-livekit-server.com",
	LiveKitAPIKey:    os.Getenv("LIVEKIT_API_KEY"),
	LiveKitAPISecret: os.Getenv("LIVEKIT_API_SECRET"),
})
if err != nil {
	return err
}

// Wait for avatar to join
err = session.WaitForJoin(ctx, 30*time.Second)
if err != nil {
	return err
}

// Stream TTS audio to avatar
audioOut := session.AudioOutput()
audioOut.CaptureFrame(ctx, pcmFrame)
audioOut.Flush(ctx)

// Clean up
session.Close(ctx)

Configuration

Required environment variables:

  • BITHUMAN_API_KEY: Your bitHuman API key

Required configuration:

  • AgentID: The bitHuman agent ID to use for the session

Optional configuration:

Agents

bitHuman uses agents to define avatar appearance and behavior. Agents can be realistic humans or animated characters. Create agents via the bitHuman dashboard or API.

Audio Format

bitHuman expects audio at 24kHz sample rate, mono, PCM16 format. The DataStreamAudioOutput automatically handles streaming to the avatar.

Features

  • Realistic and animated character support
  • CPU-only rendering (no GPU required)
  • <100ms latency
  • LiveKit native integration
  • Self-hostable for privacy

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the bithuman-go SDK for avatar session management.

func NewClient

func NewClient(cfg ClientConfig) (*Client, error)

NewClient creates a new bitHuman API client using the bithuman-go SDK.

func (*Client) CreateSession

func (c *Client) CreateSession(ctx context.Context, req CreateSessionRequest) (*CreateSessionResponse, error)

CreateSession creates a new real-time session with the bitHuman API.

This initiates the avatar session. If LiveKitURL and LiveKitToken are provided, the avatar will connect to the specified external LiveKit room. Otherwise, bitHuman provides its own LiveKit connection details.

func (*Client) EndSession

func (c *Client) EndSession(ctx context.Context, sessionID string) error

EndSession ends an active session.

This stops the avatar and cleans up resources on the bitHuman side.

func (*Client) GetAgent

func (c *Client) GetAgent(ctx context.Context, agentID string) (*api.Agent, error)

GetAgent retrieves agent details.

func (*Client) SDK

func (c *Client) SDK() *bithumansdk.Client

SDK returns the underlying bithuman-go SDK client for advanced usage.

func (*Client) Speak

func (c *Client) Speak(ctx context.Context, agentID string, text string) error

Speak makes the agent speak the given text.

type ClientConfig

type ClientConfig struct {
	// APIKey is the bitHuman API key.
	// Required.
	APIKey string

	// BaseURL is the bitHuman API base URL.
	// Default: https://api.bithuman.ai
	BaseURL string

	// HTTPClient is an optional custom HTTP client.
	// Default: http.Client with 30s timeout
	HTTPClient *http.Client
}

ClientConfig configures the bitHuman API client.

type CreateSessionRequest

type CreateSessionRequest struct {
	// AgentID is the bitHuman agent to use for this session.
	// Required.
	AgentID string

	// LiveKitURL is the LiveKit WebSocket URL for the avatar to connect to.
	// Optional - if provided, avatar will join the specified LiveKit room.
	LiveKitURL string

	// LiveKitToken is the JWT token for the avatar to join the room.
	// Optional - if provided with LiveKitURL, avatar uses external LiveKit.
	LiveKitToken string
}

CreateSessionRequest is the request to create a real-time session.

type CreateSessionResponse

type CreateSessionResponse struct {
	// SessionID is the unique identifier for the session.
	SessionID string

	// LiveKitURL is the LiveKit WebSocket URL (if using bitHuman's LiveKit).
	LiveKitURL string

	// LiveKitToken is the JWT token for the avatar (if using bitHuman's LiveKit).
	LiveKitToken string
}

CreateSessionResponse is the response from creating a session.

type Session

type Session struct {
	*avatar.BaseSession
	// contains filtered or unexported fields
}

Session implements avatar.Session for bitHuman avatars.

func NewSession

func NewSession(cfg SessionConfig) (*Session, error)

NewSession creates a new bitHuman avatar session.

func (*Session) AgentID

func (s *Session) AgentID() string

AgentID returns the bitHuman agent ID.

func (*Session) Close

func (s *Session) Close(ctx context.Context) error

Close disconnects the avatar and cleans up resources.

func (*Session) SessionID

func (s *Session) SessionID() string

SessionID returns the bitHuman session ID.

func (*Session) Start

func (s *Session) Start(ctx context.Context, opts avatar.StartOptions) error

Start initializes the bitHuman avatar session.

This method:

  1. Validates the start options
  2. Generates a LiveKit token for the avatar
  3. Creates a session with the bitHuman API
  4. Sets up the audio output for streaming
  5. Registers room callbacks to track the avatar participant

func (*Session) WaitForJoin

func (s *Session) WaitForJoin(ctx context.Context, timeout time.Duration) error

WaitForJoin blocks until the avatar participant joins the room.

type SessionConfig

type SessionConfig struct {
	// APIKey is the bitHuman API key.
	// Required.
	APIKey string

	// BaseURL is the bitHuman API base URL.
	// Default: https://api.bithuman.ai
	BaseURL string

	// AgentID is the bitHuman agent to use for this session.
	// Required.
	AgentID string

	// AudioConfig configures the audio format.
	// Default: 24kHz mono PCM16
	AudioConfig avatar.AudioConfig
}

SessionConfig configures a bitHuman avatar session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL