xiaozhi-esp32-server/main/xiaozhi-server/TENVAD_INTEGRATION.md
rahulpscraftech360 5db5e26119 ten VAD added
2025-08-13 11:52:38 +05:30

4.2 KiB

TEN VAD Integration Summary

Overview

TEN VAD has been successfully integrated into the XiaoZhi ESP32 Server as an alternative Voice Activity Detection (VAD) provider alongside the existing Silero VAD.

Files Added/Modified

New Files Created:

  1. core/providers/vad/ten_vad.py - Main TEN VAD provider implementation
  2. scripts/install_ten_vad.py - Installation script for TEN VAD
  3. scripts/test_ten_vad.py - Test script to verify TEN VAD installation
  4. examples/ten_vad_example.py - Usage example and configuration guide
  5. docs/ten-vad-integration.md - Comprehensive integration documentation

Modified Files:

  1. requirements.txt - Added ten-vad==0.1.0 dependency
  2. data/.config.yaml - Added TEN VAD configuration section
  3. README.md - Updated VAD section to include TEN VAD

Configuration

TEN VAD configuration has been added to .config.yaml:

VAD:
  TenVAD:
    type: ten_vad
    model_path: models/ten-vad
    sample_rate: 16000
    frame_size: 512
    threshold: 0.5
    threshold_low: 0.2
    min_silence_duration_ms: 1000
    frame_window_threshold: 3

Usage

To use TEN VAD, update the selected module in your configuration:

selected_module:
  VAD: TenVAD  # Change from SileroVAD to TenVAD

Installation Steps

  1. Install TEN VAD package:

    cd main/xiaozhi-server
    python scripts/install_ten_vad.py
    
  2. Test the installation:

    python scripts/test_ten_vad.py
    
  3. Update configuration:

    selected_module:
      VAD: TenVAD
    
  4. Start the server:

    python app.py
    

Key Features

  • High Performance: TEN VAD provides accurate voice activity detection
  • Configurable Thresholds: Dual threshold system for stable detection
  • Sliding Window: Prevents false positives with frame-based detection
  • Easy Integration: Follows the same interface as existing VAD providers
  • Comprehensive Logging: Debug information for troubleshooting

Architecture Integration

TEN VAD integrates seamlessly with the existing VAD architecture:

core/utils/vad.py (Factory)
    ↓
core/providers/vad/ten_vad.py (TEN VAD Implementation)
    ↓
core/providers/vad/base.py (VAD Interface)

The integration follows the same pattern as other VAD providers:

  • Implements VADProviderBase interface
  • Uses the factory pattern for instantiation
  • Processes Opus-encoded audio packets
  • Returns boolean voice activity detection results

Configuration Options

Sensitivity Levels:

  • Sensitive: threshold: 0.3, threshold_low: 0.1
  • Balanced: threshold: 0.5, threshold_low: 0.2 (default)
  • Conservative: threshold: 0.7, threshold_low: 0.4

Performance Tuning:

  • frame_size: Audio processing frame size (default: 512)
  • frame_window_threshold: Frames needed for voice detection (default: 3)
  • min_silence_duration_ms: Silence duration to end speech (default: 1000ms)

Testing

The integration includes comprehensive testing:

  1. Installation Test: Verifies TEN VAD package installation
  2. Provider Creation Test: Tests VAD provider instantiation
  3. Audio Processing Test: Tests audio processing pipeline
  4. Configuration Loading Test: Tests factory method integration

Troubleshooting

Common issues and solutions:

  1. Import Error: Install TEN VAD with pip install ten-vad
  2. Model Loading Error: Ensure model path exists and is accessible
  3. Performance Issues: Adjust frame_size or sample_rate
  4. Detection Issues: Tune threshold values for your environment

Documentation

  • Integration Guide: docs/ten-vad-integration.md
  • Usage Example: examples/ten_vad_example.py
  • Installation Script: scripts/install_ten_vad.py
  • Test Script: scripts/test_ten_vad.py

Next Steps

  1. Test TEN VAD with real audio input
  2. Compare performance with Silero VAD
  3. Fine-tune configuration parameters
  4. Consider adding more VAD providers if needed

Notes

  • TEN VAD models will be downloaded automatically on first use
  • The integration maintains backward compatibility with existing VAD providers
  • All existing VAD functionality remains unchanged
  • TEN VAD can be easily switched on/off via configuration