UNPKG

aixblock-voice-ai-deepgram

Version:

A React component for real-time transcription and voice agent interactions using Deepgram APIs

153 lines (152 loc) 4.08 kB
/** * DeepgramVoiceInteraction Type Definitions */ import type { ConnectionState, ServiceType, EndpointConfig, DeepgramError } from './connection'; import type { TranscriptionOptions, TranscriptResponse } from './transcription'; import type { AgentState, AgentOptions, UpdateInstructionsPayload } from './agent'; export * from './agent'; export * from './connection'; export * from './transcription'; export * from './voiceBot'; export * from './voiceConfig'; /** * LLM response format */ export interface LLMResponse { type: 'llm'; text: string; metadata?: any; } /** * User message response format */ export interface UserMessageResponse { type: 'user'; text: string; metadata?: any; } /** * Props for the DeepgramVoiceInteraction component * This interface uses AgentState, AgentOptions, etc. */ export interface DeepgramVoiceInteractionProps { /** * Deepgram API key */ apiKey: string; /** * Options for the transcription service */ transcriptionOptions?: TranscriptionOptions; /** * Options for the agent service */ agentOptions?: AgentOptions; /** * Configuration for API endpoints */ endpointConfig?: EndpointConfig; /** * Called when the component is ready (initialized, mic permissions, etc.) */ onReady?: (isReady: boolean) => void; /** * Called when the connection state of either service changes */ onConnectionStateChange?: (service: ServiceType, state: ConnectionState) => void; /** * Called when a new transcript is received */ onTranscriptUpdate?: (transcriptData: TranscriptResponse) => void; /** * Called when the agent's state changes */ onAgentStateChange?: (state: AgentState) => void; /** * Called when the agent produces text output */ onAgentUtterance?: (utterance: LLMResponse) => void; /** * Called when a user message is received from the server (role:user in ConversationText) */ onUserMessage?: (message: UserMessageResponse) => void; /** * Called when audio playback state changes */ onPlaybackStateChange?: (isPlaying: boolean) => void; /** * Called when the user starts speaking (based on VAD/endpointing) */ onUserStartedSpeaking?: () => void; /** * Called when the user stops speaking (based on VAD/endpointing) */ onUserStoppedSpeaking?: () => void; /** * Called when an error occurs */ onError?: (error: DeepgramError) => void; /** * Called when have new audio buffer */ onAgentAudioUpdate?: (data: ArrayBuffer) => void; /** * Enable verbose logging */ debug?: boolean; /** * Options for auto-sleep functionality */ sleepOptions?: { /** * Enable auto-sleep after inactivity */ autoSleep?: boolean; /** * Seconds of inactivity before auto-sleep (default: 30) */ timeout?: number; /** * Phrases that can wake the agent from sleep */ wakeWords?: string[]; }; } /** * Control methods for the DeepgramVoiceInteraction component * This interface uses UpdateInstructionsPayload */ export interface DeepgramVoiceInteractionHandle { /** * Start the voice interaction */ start: () => Promise<void>; /** * Stop the voice interaction */ stop: () => Promise<void>; /** * Update the agent's instructions or context during an active session */ updateAgentInstructions: (payload: UpdateInstructionsPayload) => void; /** * Interrupt the agent while it is speaking */ interruptAgent: () => void; /** * Put the agent to sleep */ sleep: () => void; /** * Wake the agent from sleep */ wake: () => void; /** * Toggle between sleep and wake states */ toggleSleep: () => void; /** * Inject a message directly to the agent */ injectAgentMessage: (message: string) => void; }