1.0.7 • Published 9 months ago

@atrix.dev/ai-voice-sdk v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

AI Voice Caller SDK

Create AI-powered voice calls with natural language processing and voice synthesis.

Features

CategoryFeatures
Voice Calls• Outbound calls• SMS messaging• Real-time call monitoring• Call status tracking• Concurrent call handling
AI Integration• Natural voice synthesis• Multi-voice support• Emotion detection• Conversation management• Context awareness
Analytics• Call metrics tracking• Cost monitoring• Success rate analysis• Duration tracking• Sentiment analysis
Developer Tools• WebSocket monitoring• Caching system• Rate limiting• Health checks• Detailed logging

Installation

npm install @atrix.dev/ai-voice-sdk

Quick Start

import { AIVoiceCaller } from '@atrix.dev/ai-voice-sdk';

// Initialize the SDK
const voiceCaller = new AIVoiceCaller({
  apiKey: 'your_api_key',
  twilioAccountSid: 'your_twilio_sid',
  twilioAuthToken: 'your_twilio_token',
  twilioPhoneNumber: 'your_twilio_number',
  elevenLabsApiKey: 'your_elevenlabs_key',
  elevenLabsVoiceId: 'your_voice_id'
});

// Make a call
const result = await voiceCaller.makeCall({
  to: '+1234567890',
  message: 'Hello from AI Voice!'
});

// Send an SMS
const sms = await voiceCaller.sendSMS(
  '+1234567890', 
  'Hello from AI Voice!'
);

Configuration Options

OptionTypeRequiredDefaultDescription
apiKeystring-Your Atrix API key
twilioAccountSidstring-Twilio Account SID
twilioAuthTokenstring-Twilio Auth Token
twilioPhoneNumberstring-Your Twilio phone number
elevenLabsApiKeystring-ElevenLabs API key
elevenLabsVoiceIdstring-ElevenLabs voice ID
baseUrlstring-https://api.atrix.devAPI base URL
logLevelstring-'info'Logging level (debug/info/warn/error)
maxConcurrentCallsnumber-5Maximum concurrent calls
cacheTTLnumber-300000Cache TTL in milliseconds
cacheMaxSizenumber-1000Maximum cache entries
retryAttemptsnumber-3Number of retry attempts
timeoutnumber-30000Request timeout in milliseconds

API Reference

Voice Calls

// Make a voice call
const call = await voiceCaller.makeCall({
  to: '+1234567890',
  message: 'Hello!',
  voiceSettings: {
    stability: 0.7,
    similarityBoost: 0.5,
    style: 0.5,
    useSpeakerBoost: true
  }
});

// End a call
await voiceCaller.endCall('call_id');

// Get call history
const history = await voiceCaller.getCallHistory(10);

// Get call metrics
const metrics = await voiceCaller.getCallMetrics('call_id');

SMS Messaging

// Send SMS
const sms = await voiceCaller.sendSMS(
  '+1234567890',
  'Hello from AI Voice!'
);

Real-time Monitoring

// Listen for call status updates
voiceCaller.onCallStatus((status) => {
  console.log('Call status:', status);
});

// Listen for errors
voiceCaller.onError((error) => {
  console.error('Error:', error);
});

Analytics & Metrics

// Get aggregate metrics
const metrics = await voiceCaller.getMetrics();

// Get conversation transcript
const transcript = await voiceCaller.getConversationTranscript('call_id', {
  format: 'json',
  includeTiming: true,
  speakerLabels: true
});

Error Handling

Error CodeDescriptionCommon Causes
INVALID_CONFIGConfiguration errorMissing required fields, invalid format
TWILIO_ERRORTwilio API errorInvalid credentials, rate limits
ELEVENLABS_ERRORElevenLabs API errorInvalid API key, voice ID
NETWORK_ERRORNetwork request failedTimeout, connection issues
CALL_FAILEDCall operation failedInvalid phone number, service unavailable
SMS_FAILEDSMS operation failedInvalid phone number, service unavailable
VALIDATION_ERRORInput validation failedInvalid phone format, missing data

Best Practices

  1. Rate Limiting

    • Monitor your API usage
    • Implement proper error handling
    • Use the built-in rate limiter
  2. Resource Management

    • Clean up resources with disconnect()
    • Monitor memory usage with metrics
    • Use caching for frequent requests
  3. Error Handling

    • Always implement error handlers
    • Use try-catch blocks
    • Monitor error rates
  4. Performance

    • Enable caching for repeated calls
    • Use concurrent call limits
    • Monitor call metrics

Examples

Advanced Call Setup

const call = await voiceCaller.makeCall({
  to: '+1234567890',
  message: 'Hello!',
  voiceSettings: {
    stability: 0.7,
    similarityBoost: 0.5,
    style: 0.5,
    useSpeakerBoost: true
  },
  webhookEvents: ['initiated', 'ringing', 'answered', 'completed'],
  callbackUrl: 'https://your-webhook.com/callback'
});

Health Monitoring

// Check service health
const isHealthy = await voiceCaller.checkHealth();

// Clear cache if needed
await voiceCaller.clearCache();

// Disconnect services
voiceCaller.disconnect();

Support

License

MIT

1.0.7

9 months ago

1.0.6

9 months ago

1.0.4

9 months ago

1.0.0

9 months ago