Skip to main content
Normalized for Mintlify from knowledge-base/aiconnected-apps-and-modules/modules/aiConnected-voice/voice-pipeline-architecture.mdx.

Voice by aiConnected — Voice Pipeline Architecture \

Document Information \


Table of Contents \

Voice by aiConnected — Voice Pipeline Architecture Document Information Table of Contents 1. Introduction 1.1 Purpose 1.2 Scope 1.3 Design Goals 1.4 Key Terminology 2. Pipeline Overview 2.1 High-Level Architecture 2.2 Component Summary 2.3 Data Flow Summary 2.4 Pipeline States 3. Latency Budget 3.1 Target Latency 3.2 Latency Budget Breakdown 3.3 Latency Optimization Strategies 3.4 Latency Monitoring Points 3.5 Latency Alerts 4. Voice Activity Detection 4.1 VAD Overview 4.2 Silero VAD Integration 4.3 Endpointing Strategies 4.4 VAD Configuration by Use Case 5. Speech-to-Text Integration 5.1 Deepgram Nova-2 5.2 Deepgram Client 5.3 Transcript Processing 5.4 STT Fallback Strategy 6. Context Assembly 6.1 Context Overview 6.2 Context Assembly Pipeline 6.3 Context Manager Implementation 6.4 System Prompt Templates 7. LLM Integration 7.1 Claude API Integration 7.2 Response Routing 7.3 LLM Fallback Strategy 8. Text-to-Speech Integration 8.1 Chatterbox TTS 8.2 Chatterbox Client 8.3 TTS Fallback Strategy 8.4 Voice Configuration 9. Streaming Architecture 9.1 End-to-End Streaming 9.2 Pipeline Orchestrator 9.3 Audio Buffer Management 10. Interruption Handling 10.1 Interruption Types 10.2 Interruption Detection 10.3 Graceful Interruption Flow 10.4 Backchannel Recognition 11. Tool Calling in Voice Context 11.1 Voice-Appropriate Tools 11.2 Tool Executor 11.3 Webhook Integration with n8n 12. Conversation State Management 12.1 State Structure 12.2 State Manager 13. Error Handling and Fallbacks 13.1 Error Categories 13.2 Error Handler 13.3 Fallback Hierarchy 14. Performance Optimization 14.1 Optimization Techniques 14.2 Connection Management 14.3 Phrase Caching 15. Monitoring and Debugging 15.1 Metrics 15.2 Logging 15.3 Debug Tools Appendix A: Configuration Reference Appendix B: Sequence Diagrams B.1 Normal Turn Flow Document History

  1. Introduction \

1.1 Purpose \

This document specifies the voice pipeline architecture for Voice by aiConnected. The voice pipeline is the core processing chain that transforms caller speech into AI responses and back to synthesized speech. This is where the “magic” happens—creating the illusion of a natural, responsive AI conversation partner. The pipeline must achieve sub-second response times to feel natural while maintaining conversation coherence, handling interruptions gracefully, and executing tool calls seamlessly.

1.2 Scope \

This document covers:
  • Complete audio processing pipeline from microphone to speaker
  • Component-level architecture for VAD, STT, LLM, and TTS
  • Streaming strategies for minimal latency
  • Interruption detection and handling
  • Tool calling integration in voice context
  • Conversation state management
  • Error handling and fallback strategies
This document does not cover:
  • Telephony integration (see ARCH-002)
  • LiveKit room management (see ARCH-004)
  • Business logic for specific use cases

1.3 Design Goals \

1.4 Key Terminology \


  1. Pipeline Overview \

2.1 High-Level Architecture \

2.2 Component Summary \

2.3 Data Flow Summary \

2.4 Pipeline States \


  1. Latency Budget \

3.1 Target Latency \

Human conversation has natural response gaps. Studies show:
  • 200-300ms: Feels instantaneous, slightly unnatural
  • 500-700ms: Natural conversation pace
  • 800-1000ms: Acceptable, feels thoughtful
  • >1200ms: Noticeably slow, awkward
Our target: < 1000ms end-to-end with < 500ms time-to-first-byte.

3.2 Latency Budget Breakdown \

3.3 Latency Optimization Strategies \

3.4 Latency Monitoring Points \

3.5 Latency Alerts \


  1. Voice Activity Detection \

4.1 VAD Overview \

Voice Activity Detection is the first processing stage, determining when the caller is speaking. Good VAD is critical for:
  • Knowing when to start transcription
  • Detecting end of utterance (endpointing)
  • Detecting interruptions during AI speech

4.2 Silero VAD Integration \

We use Silero VAD, a lightweight neural network model optimized for real-time processing.

4.3 Endpointing Strategies \

Endpointing determines when a speaker has finished their turn. Multiple strategies can be combined:

4.4 VAD Configuration by Use Case \


  1. Speech-to-Text Integration \

5.1 Deepgram Nova-2 \

We use Deepgram Nova-2 for streaming speech-to-text:
  • Accuracy: 95%+ word accuracy
  • Latency: ~100ms interim, ~200ms final
  • Features: Streaming, punctuation, word timestamps
  • Languages: 36+ languages supported

5.2 Deepgram Client \

5.3 Transcript Processing \

5.4 STT Fallback Strategy \


  1. Context Assembly \

6.1 Context Overview \

Before sending to the LLM, we assemble a complete context including:
  • System prompt with agent personality
  • Knowledge base context
  • Conversation history
  • Tool definitions
  • Current user input

6.2 Context Assembly Pipeline \

6.3 Context Manager Implementation \

6.4 System Prompt Templates \


  1. LLM Integration \

7.1 Claude API Integration \

We use Claude Sonnet for response generation via streaming API:

7.2 Response Routing \

Determine whether LLM output should be spoken or is a tool call:

7.3 LLM Fallback Strategy \


  1. Text-to-Speech Integration \

8.1 Chatterbox TTS \

We use Chatterbox TTS self-hosted on RunPod for zero per-minute cost:
  • Quality: Natural, expressive speech
  • Latency: ~150ms TTFB
  • Streaming: Chunk-based audio output
  • Cost: Fixed GPU cost, no per-minute fees

8.2 Chatterbox Client \

8.3 TTS Fallback Strategy \

8.4 Voice Configuration \


  1. Streaming Architecture \

9.1 End-to-End Streaming \

The entire pipeline operates in streaming mode to minimize latency:

9.2 Pipeline Orchestrator \

9.3 Audio Buffer Management \


  1. Interruption Handling \

10.1 Interruption Types \

Users may interrupt the AI for various reasons:

10.2 Interruption Detection \

10.3 Graceful Interruption Flow \

10.4 Backchannel Recognition \


  1. Tool Calling in Voice Context \

11.1 Voice-Appropriate Tools \

Tools in voice context need special handling:
  • Results must be speakable
  • Execution should be fast
  • Failures need graceful verbal handling

11.2 Tool Executor \

11.3 Webhook Integration with n8n \


  1. Conversation State Management \

12.1 State Structure \

12.2 State Manager \


  1. Error Handling and Fallbacks \

13.1 Error Categories \

13.2 Error Handler \

13.3 Fallback Hierarchy \


  1. Performance Optimization \

14.1 Optimization Techniques \

14.2 Connection Management \

14.3 Phrase Caching \


  1. Monitoring and Debugging \

15.1 Metrics \

15.2 Logging \

15.3 Debug Tools \




Document History \


End of Document