ug-js-sdk
v3.0.51
Published
JavaScript SDK for building conversational AI experiences with voice, text, avatars, and real-time interactions
Maintainers
Readme
UG JS SDK
JavaScript SDK for building conversational AI experiences with voice, text, avatars, and real-time interactions.
Installation
npm install ug-js-sdkQuick Start
import { ConversationManager } from 'ug-js-sdk'
const conversation = new ConversationManager({
apiUrl: 'wss://pug.stg.uglabs.app',
apiKey: 'your-api-key',
federatedId: 'user-123',
prompt: 'You are a friendly assistant.',
hooks: {
onStateChange: (state) => console.log('State:', state),
onTextMessage: (event) => console.log('Assistant:', event.text),
onError: (error) => console.error('Error:', error.message),
},
})
// Start the conversation
await conversation.start()
// Send text input
await conversation.sendText('Hello!')
// Or enable voice input
await conversation.startListening()Features
- Voice Input/Output - Real-time speech-to-text and text-to-speech
- Text Chat - Send and receive text messages
- Avatar Support - Lip-sync animations with viseme data
- Subtitles - Real-time captions with word highlighting
- Utilities - Built-in classifiers and extractors for AI operations
- Safety Policies - Content filtering and moderation
- Image Generation - Generate images via Bria or Replicate
Configuration
const config: ConversationConfig = {
apiUrl: 'wss://pug.stg.uglabs.app',
apiKey: 'your-api-key',
federatedId: 'user-id',
prompt: 'Your system prompt here',
// Optional: Configure capabilities
capabilities: {
audio: true,
subtitles: true,
viseme: false,
avatar: false,
},
// Optional: Voice settings
voiceProfile: {
voice_id: 'voice-id',
speed: 1.0,
},
hooks: {
onStateChange: (state) => { /* handle state */ },
onTextMessage: (event) => { /* handle text */ },
onSubtitleChange: (subtitle) => { /* handle subtitles */ },
onError: (error) => { /* handle errors */ },
},
}Conversation States
The SDK manages the following states:
| State | Description |
|-------|-------------|
| uninitialized | Before connection |
| initializing | Connecting to server |
| idle | Ready for interaction |
| listening | Listening for voice input |
| userSpeaking | User is speaking |
| waiting | Processing input |
| playing | Playing audio response |
Documentation
For full documentation, API reference, and examples visit:
License
MIT
