UNPKG

voice-agent

Version:

A Vue.js voice agent plugin for real-time voice communication via WebSocket

93 lines (92 loc) 2.2 kB
import { VoiceAgentConfig } from '../types'; import { Ref } from 'vue'; interface MessageHandlerCallbacks { onReady?: () => void; scrollToBottom?: () => void; initAudioQueueManager?: () => void; } interface AudioQueueManager { interrupt(): void; enqueueAudio(audioData: string, message?: ConversationMessage): void; } interface ConversationMessage { id: number; type: 'user' | 'assistant'; content: string; timestamp: Date; audioData?: string | null; isLoading?: boolean; isStreaming?: boolean; hasStartedPlaying?: boolean; isPlaying?: boolean; hasAudio?: boolean; textComplete?: boolean; audioInstance?: HTMLAudioElement | null; } export declare class MessageHandler { private config; private callbacks; private audioOutputCache; private textOutputCache; private currentUserMessage; private currentAssistantMessage; private shouldDiscardAudio; /** * 初始化配置和回调 */ init(config: VoiceAgentConfig, callbacks?: MessageHandlerCallbacks): void; /** * 处理WebSocket消息 */ handleMessage(messageData: string, conversationList: Ref<ConversationMessage[]>, audioQueueManager?: AudioQueueManager): void; /** * 处理ready消息 */ private handleReady; /** * 处理语音开始 */ private handleSpeechStart; /** * 处理语音结束 */ private handleSpeechStop; /** * 处理转录完成 */ private handleTranscriptDone; /** * 处理响应创建 */ private handleResponseCreate; /** * 处理文本输出 */ private handleTextOutput; /** * 处理音频输出 */ private handleAudioOutput; /** * 处理音频完成 */ private handleAudioDone; /** * 处理文本完成 */ private handleTextDone; /** * 处理最终响应 */ private handleFinalResponse; /** * 清理对话记录 */ clearConversation(conversationList: Ref<ConversationMessage[]>): void; /** * 重置状态 */ reset(): void; } export {}; //# sourceMappingURL=messageHandler.d.ts.map