UNPKG

ttc-ai-client

Version:

TypeScript client sdk for TTC AI services with decorators and schema validation.

104 lines 3.87 kB
"use strict"; /** * Example usage of TTC Simple Call Integration * * This example shows how to use the simple voice call system independently * for projects that need speech capabilities without the full widget. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.exampleDirectVoiceManager = exports.exampleCallIntegration = exports.createSimpleSpeechIntegration = void 0; const exports_1 = require("../calls/exports"); /** * Example 1: Using CallIntegration (recommended for most use cases) */ async function exampleCallIntegration() { const callIntegration = new exports_1.CallIntegration({ conversationId: 'example-conversation', token: 'your-auth-token', serverUrl: 'ws://localhost:8080', // Handle user speech (send to TTC, response comes via ttc.subscribe) onUserMessage: (userText) => { console.log('User said:', userText); // Send to TTC system for AI processing // Response will come back via ttc.subscribe('message', callback) // In a real implementation, you'd send this to TTC like: // ttc.server.ttcCore.chatAI(chatId, userText); }, // Callbacks for call lifecycle onCallStart: () => { console.log('Voice call started'); }, onCallEnd: () => { console.log('Voice call ended'); }, onError: (error) => { console.error('Call error:', error); }, onStatusChange: (status) => { console.log('Status:', status); } }); // Start and end calls console.log('Starting call integration example...'); callIntegration.startCall(); // End call after 30 seconds for demo setTimeout(() => { callIntegration.endCall(); }, 30000); } exports.exampleCallIntegration = exampleCallIntegration; /** * Example 2: Using VoiceCallManager directly (for advanced use cases) */ async function exampleDirectVoiceManager() { const voiceManager = new exports_1.VoiceCallManager({ conversationId: 'direct-example', token: 'your-auth-token', serverUrl: 'ws://localhost:8080', // Handle user speech directly onUserSpeech: (text) => { console.log('User speech received:', text); // Process the speech and respond setTimeout(() => { voiceManager.respondWithSpeech(`You said: ${text}`); }, 1000); }, onCallStart: () => { console.log('Direct call started'); }, onCallEnd: () => { console.log('Direct call ended'); }, onError: (error) => { console.error('Direct call error:', error); } }); // Start call console.log('Starting direct voice manager example...'); voiceManager.startCall(); // End call after 30 seconds for demo setTimeout(() => { voiceManager.endCall(); }, 30000); } exports.exampleDirectVoiceManager = exampleDirectVoiceManager; /** * Example 3: Simple integration function for easy setup */ function createSimpleSpeechIntegration(options) { return new exports_1.CallIntegration({ conversationId: options.conversationId, token: options.token, serverUrl: 'ws://localhost:8080', onUserMessage: options.onMessage || ((text) => console.log('User said:', text)), onCallStart: () => console.log('Call started'), onCallEnd: () => console.log('Call ended'), onError: (error) => console.error('Call error:', error), onStatusChange: (status) => console.log('Status:', status) }); } exports.createSimpleSpeechIntegration = createSimpleSpeechIntegration; // Demo usage (uncomment to test) // exampleCallIntegration(); // exampleDirectVoiceManager(); //# sourceMappingURL=speechExample.js.map