UNPKG

aixblock-voice-ai-deepgram

Version:

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

86 lines (85 loc) 2.05 kB
import { AgentState, ConnectionState, ServiceType } from '../../types'; /** * State of the voice interaction component */ export interface VoiceInteractionState { /** * Connection states for each service */ connections: Record<ServiceType, ConnectionState>; /** * Current state of the agent */ agentState: AgentState; /** * Microphone permission status */ microphonePermission: 'granted' | 'denied' | 'prompt'; /** * Whether audio recording is active */ isRecording: boolean; /** * Whether audio playback is active */ isPlaying: boolean; /** * Overall ready state of the component */ isReady: boolean; /** * Error state */ error: string | null; } /** * Events that can change the state */ export type StateEvent = { type: 'CONNECTION_STATE_CHANGE'; service: ServiceType; state: ConnectionState; } | { type: 'AGENT_STATE_CHANGE'; state: AgentState; } | { type: 'MICROPHONE_PERMISSION_CHANGE'; status: 'granted' | 'denied' | 'prompt'; } | { type: 'RECORDING_STATE_CHANGE'; isRecording: boolean; } | { type: 'PLAYBACK_STATE_CHANGE'; isPlaying: boolean; } | { type: 'READY_STATE_CHANGE'; isReady: boolean; } | { type: 'ERROR'; message: string | null; }; /** * Initial state */ export declare const initialState: VoiceInteractionState; /** * Reducer function to update state based on events */ export declare function stateReducer(state: VoiceInteractionState, event: StateEvent): VoiceInteractionState; /** * Derived state properties */ export declare const derivedStates: { /** * Checks if all services are connected */ isFullyConnected: (state: VoiceInteractionState) => boolean; /** * Checks if any service has an error */ hasConnectionError: (state: VoiceInteractionState) => boolean; /** * Gets overall connection status */ overallConnectionStatus: (state: VoiceInteractionState) => ConnectionState; };