Overview
Concrete voice activity detection and speech-to-text pipeline that captures microphone audio, detects speech segments via Web Audio API, and transcribes via ElevenLabs STT for the voice-input intervention type.
Description
The VAD Detector (Voice Activity Detection) and ElevenLabs STT modules work together to enable voice input for the intervention system. The VAD detector uses the Web Audio API (`AudioContext`, `MediaStreamSource`, `AnalyserNode`) to monitor microphone input in real-time. It computes frequency data and applies an energy threshold to detect when speech starts and when silence indicates speech end. When speech ends, the captured audio segment is sent to the ElevenLabs speech-to-text API (or a server-based STT endpoint) for transcription. The transcribed text is returned as the intervention result.
Usage
- Used internally by the voice-input intervention implementation.
- Start recording: initialize VAD with microphone stream and silence threshold.
- On speech end: send audio to STT, return transcribed text.
Code Reference
Source Location
- Repository: AIPex
- File: packages/aipex-react/src/lib/voice/vad-detector.ts
- Lines: L1-268 (VAD detector)
- Support: packages/aipex-react/src/lib/voice/elevenlabs-stt.ts:L1-188 (STT transcription), packages/aipex-react/src/lib/voice/server-stt.ts:L1-155 (server STT alternative)
Signature
// VAD Detector (conceptual interface)
interface VADDetector {
start(stream: MediaStream): void
stop(): void
onSpeechStart?: () => void
onSpeechEnd?: (audioBlob: Blob) => void
onNoise?: (level: number) => void
}
// ElevenLabs STT
async function transcribeAudio(
audioBlob: Blob,
options?: { apiKey?: string; model?: string }
): Promise<string>
// Server STT (alternative)
async function transcribeViaServer(
audioBlob: Blob,
endpoint: string
): Promise<string>
Import
import { /* VAD detector */ } from "@aipexstudio/aipex-react/lib/voice";
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| stream |
MediaStream |
Yes |
Microphone audio stream
|
| audioBlob |
Blob |
Yes (STT) |
Audio segment to transcribe
|
Outputs
| Name |
Type |
Description
|
| onSpeechEnd |
Blob |
Audio segment when speech ends
|
| transcribeAudio |
string |
Transcribed text from STT service
|
Usage Examples
Voice Input Pipeline
// Internal to voice-input intervention implementation:
// 1. Start VAD with microphone
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const vad = createVADDetector({
onSpeechEnd: async (audioBlob) => {
// 2. Send audio to STT
const text = await transcribeAudio(audioBlob, { apiKey: elevenLabsKey });
// 3. Return transcribed text as intervention result
resolve({ success: true, data: text, status: "completed" });
},
});
vad.start(stream);
// User speaks → VAD detects speech → silence → onSpeechEnd fires
// → STT transcribes → text returned to AI agent
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.