Skip to main content
Hamsa Voice Agents Web SDK is a JavaScript library for integrating voice agents from Hamsa into your web applications. It provides high-quality real-time audio communication for voice interactions in the browser.

Installation

Install the SDK via npm:

Usage

Using via npm

First, import the package in your code:
Initialize the SDK with your API key:

Using via CDN

Include the script from a CDN:
Then, you can initialize the agent like this:
Make sure to replace LATEST_VERSION with the actual latest version number.

Start a Conversation with an Existing Agent

Start a conversation with an existing agent by calling the “start” function. You can create and manage agents in our Dashboard or using our API (see: Documentation Page):
When creating an agent, you can add parameters to your pre-defined values. For example, you can set your Greeting Message to: “Hello {{name}}, how can I help you today?” and pass the “name” as a parameter to use the correct name of the user.

Pause/Resume a Conversation

To pause the conversation, call the “pause” function. This will prevent the SDK from sending or receiving new data until you resume the conversation:
To resume the conversation:

End a Conversation

To end a conversation, simply call the “end” function:

Advanced Audio Controls

The SDK provides comprehensive audio control features for professional voice applications:

Volume Management

Microphone Control

Audio Visualization

Create real-time audio visualizers using frequency data:

Audio Capture

Capture raw audio data from the agent or user for forwarding to third-party services, custom recording, or advanced audio processing. The SDK provides three levels of API for different use cases: The easiest way - just pass a callback to start():
This automatically:
  • ✅ Captures agent audio only
  • ✅ Uses opus-webm format (efficient, compressed)
  • ✅ Delivers 100ms chunks (good balance of latency/efficiency)
  • ✅ Starts immediately when call connects
  • ✅ No timing issues or event handling needed

Level 2: Inline Configuration

Need more control? Use captureAudio options:

Level 3: Dynamic Control

For advanced users who need runtime control:

Audio Capture Formats

The SDK supports three audio formats:
  1. opus-webm (default, recommended)
    • Efficient Opus codec in WebM container
    • Small file size, good quality
    • Best for forwarding to services or recording
    • audioData is an ArrayBuffer
  2. pcm-f32
    • Raw PCM audio as Float32Array
    • Values range from -1.0 to 1.0
    • Best for audio analysis or DSP
    • audioData is a Float32Array
  3. pcm-i16
    • Raw PCM audio as Int16Array
    • Values range from -32768 to 32767
    • Best for compatibility with audio APIs
    • audioData is an Int16Array

Common Use Cases

Forward agent audio to third-party service:
Capture both agent and user audio:
Advanced: Custom audio analysis with PCM:
Real-time transcription:
TypeScript support:

Advanced Configuration Options

Platform-Specific Optimizations

Job/Call ID Tracking

Track and reference conversations using unique job IDs. The SDK provides two ways to access the job/call ID: The callStarted event includes the job ID in its data object:

Getting Job ID with Getter Method

Access the job ID anytime after the call has started:

TypeScript Support

Events

During the conversation, the SDK emits events to update your application about the conversation status.

Conversation Status Events

Agent Status Events

Conversation Script Events

Error Events

Advanced Analytics Events

The SDK provides comprehensive analytics for monitoring call quality, performance, and custom agent events:

Analytics & Monitoring

The SDK provides comprehensive real-time analytics for monitoring call quality, performance metrics, and custom agent events. Access analytics data through both synchronous methods and event-driven updates.

Analytics Architecture

The SDK uses a clean modular design with four specialized components:
  • Connection Management: Handles room connections, participants, and network state
  • Analytics Engine: Processes WebRTC statistics and performance metrics
  • Audio Management: Manages audio tracks, volume control, and quality monitoring
  • Tool Registry: Handles RPC method registration and client-side tool execution
Access analytics data through both synchronous methods and event-driven updates.

Synchronous Analytics Methods

Get real-time analytics data instantly for dashboards and monitoring:

Real-time Dashboard Example

Build live monitoring dashboards using the analytics data:

Custom Event Tracking

Track custom events from your voice agents:

Configuration Options

The SDK accepts optional configuration parameters:

Client-Side Tools

You can register client-side tools that the agent can call during conversations:

Migration from Previous Versions

If you’re upgrading from a previous version, connection details are now automatically managed and no longer need to be configured. Check the changelog for detailed migration information.

Browser Compatibility

This SDK supports modern browsers with WebRTC capabilities:
  • Chrome 60+
  • Firefox 60+
  • Safari 12+
  • Edge 79+

TypeScript Support

The SDK includes comprehensive TypeScript definitions with detailed analytics interfaces:

Use Cases

Agent State UI Updates

Real-time Call Quality Monitoring

Analytics Dashboard

Conversation Flow Analysis

Dependencies

  • livekit-client v2.15.4: Real-time communication infrastructure
  • events v3.3.0: EventEmitter for browser compatibility
The SDK uses LiveKit’s native WebRTC capabilities for high-quality real-time audio communication and comprehensive analytics.