aixblock-voice-ai-deepgram
Version:
A React component for real-time transcription and voice agent interactions using Deepgram APIs
117 lines (116 loc) • 2.64 kB
TypeScript
import { DeepgramError } from '../../types';
/**
* Event types emitted by the AudioManager
*/
export type AudioEvent = {
type: 'ready';
} | {
type: 'recording';
isRecording: boolean;
} | {
type: 'playing';
isPlaying: boolean;
} | {
type: 'error';
error: DeepgramError;
} | {
type: 'data';
data: ArrayBuffer;
};
/**
* Options for the AudioManager
*/
export interface AudioManagerOptions {
/**
* Target sample rate for microphone capture
*/
sampleRate?: number;
/**
* Output sample rate for agent audio
*/
outputSampleRate?: number;
/**
* Enable volume normalization
*/
normalizeVolume?: boolean;
/**
* Volume normalization factor (higher = quieter)
*/
normalizationFactor?: number;
/**
* Enable verbose logging
*/
debug?: boolean;
}
/**
* Manages audio capture and playback
*/
export declare class AudioManager {
private options;
private audioContext;
private workletNode;
private microphoneStream;
private sourceNode;
private isRecording;
private isPlaying;
private isInitialized;
private eventListeners;
private startTimeRef;
private analyzer;
private analyzerData;
private currentSource;
private activeSourceNodes;
/**
* Creates a new AudioManager
*/
constructor(options: Omit<AudioManagerOptions, 'processorUrl'>);
/**
* Logs a message if debug is enabled
*/
private log;
/**
* Adds an event listener
*/
addEventListener(listener: (event: AudioEvent) => void): () => void;
/**
* Emits an event to all listeners
*/
private emit;
/**
* Initializes the AudioManager
*/
initialize(): Promise<void>;
/**
* Requests microphone permissions and starts capturing audio
*/
startRecording(): Promise<void>;
/**
* Stops recording
*/
stopRecording(): void;
/**
* Queues audio data for playback using precise timing
* @param data ArrayBuffer containing audio data (Linear16 PCM expected)
*/
queueAudio(data: ArrayBuffer): Promise<void>;
/**
* Stops all audio playback and clears scheduled audio
*/
clearAudioQueue(): void;
/**
* Checks if microphone permissions are granted
*/
static checkMicrophonePermissions(): Promise<boolean>;
/**
* Cleans up resources
*/
dispose(): void;
/**
* Gets whether recording is active
*/
isRecordingActive(): boolean;
/**
* Gets whether playback is active
*/
isPlaybackActive(): boolean;
}