Skip to content

Update to Silero VAD 5#116

Merged
dnhkng merged 2 commits intomainfrom
silero-5
Jan 30, 2025
Merged

Update to Silero VAD 5#116
dnhkng merged 2 commits intomainfrom
silero-5

Conversation

@dnhkng
Copy link
Copy Markdown
Owner

@dnhkng dnhkng commented Jan 30, 2025

This pull request includes several updates to the Voice Activity Detection (VAD) model and related components, as well as improvements to the audio processing logic. The most important changes include updating the VAD model version, simplifying the VAD class, and adjusting various parameters for better performance.

Updates to VAD model and related configurations:

  • src/glados/cli.py: Updated the VAD model checksum and URL to use the new version silero_vad_v5.onnx. [1] [2]
  • src/glados/core/vad.py: Updated the VAD model path to silero_vad_v5.onnx and removed unnecessary initial hidden and cell states. Simplified the VAD class by removing the reset method and adding new methods reset_states and __call__ to handle state management and processing. [1] [2]

Adjustments to audio processing parameters:

  • src/glados/engine.py: Adjusted VAD parameters such as VAD_SIZE, VAD_THRESHOLD, BUFFER_SIZE, and PAUSE_LIMIT for improved detection accuracy and performance.

Improvements to audio processing logic:

  • src/glados/engine.py: Updated the audio_callback_for_sd_input_stream method to use the new VAD model processing method.
  • src/glados/engine.py: Added normalization to the audio data in the asr method to improve transcription accuracy.

Documentation enhancements:

  • src/glados/engine.py: Added detailed docstrings to the PersonalityPrompt class and its to_chat_message method, including information about the return type and potential exceptions.

Summary by CodeRabbit

Release Notes

  • New Features

    • Updated Voice Activity Detection (VAD) model to a newer version
  • Improvements

    • Refined audio processing parameters for more accurate voice detection
    • Enhanced audio normalization during transcription
    • Improved error handling and method documentation
    • Enhanced path handling for model configurations
  • Bug Fixes

    • Streamlined VAD processing logic
    • Ensured proper stopping of audio input stream

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 30, 2025

Walkthrough

The pull request introduces updates to the GlaDOS project, focusing on voice activity detection (VAD) and audio processing. The changes primarily involve updating the Silero VAD model version, modifying the VAD processing logic in the core components, adjusting audio processing constants, and enhancing method documentation. The modifications aim to improve the audio input handling, model initialization, and error management across multiple source files.

Changes

File Change Summary
src/glados/cli.py Updated Silero VAD model checksum, key, and download URL to version 5. Changed DEFAULT_CONFIG path to a direct string representation.
src/glados/core/asr.py Updated MODEL_PATH and TOKEN_PATH constants to Path objects. Adjusted docstring formatting in AudioTranscriber class.
src/glados/core/vad.py Significant refactoring of VAD class:
- Simplified constructor
- Replaced process_chunk with __call__
- Added reset_states method
- Updated audio processing logic
src/glados/engine.py Updated VAD-related constants. Enhanced to_chat_message method documentation. Modified audio callback and normalization. Explicit input stream stopping.
src/glados/core/phonemizer.py Changed MODEL_NAME attribute from str to Path.
src/glados/core/tts_glados.py Updated MODEL_PATH constant from str to Path.
src/glados/core/tts_kokoro.py Updated MODEL_PATH and VOICES_PATH constants from str to Path.

Sequence Diagram

sequenceDiagram
    participant User
    participant AudioEngine
    participant VADModel
    participant Transcriber

    User->>AudioEngine: Speak
    AudioEngine->>VADModel: Process Audio Chunk
    VADModel-->>AudioEngine: Voice Activity Status
    alt Voice Detected
        AudioEngine->>Transcriber: Normalize Audio
        Transcriber->>Transcriber: Transcribe
        Transcriber-->>AudioEngine: Transcription Result
    end
Loading

Possibly related PRs

  • Kokoro integration #115: The changes in src/glados/cli.py regarding the updates to MODEL_CHECKSUMS and MODEL_URLS dictionaries are directly related to the modifications made in the main PR, which also updates these dictionaries for the Silero VAD model.

Poem

🐰 Ears perked up, code refined,
VAD model dancing, redesigned!
Chunks of sound, now more precise,
Processing audio, rolling the dice 🎲
GlaDOS evolves, with rabbit-like grace! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/glados/core/vad.py (2)

8-8: Consider using Path for model path and add existence check.

While the model path update is correct, consider these improvements:

  1. Use Path for better cross-platform compatibility
  2. Add a check for model file existence during initialization
-VAD_MODEL = "./models/ASR/silero_vad_v5.onnx"
+from pathlib import Path
+VAD_MODEL = Path("./models/ASR/silero_vad_v5.onnx")

49-102: Add return type hint in docstring.

The implementation looks good, but the docstring is missing the return type hint:

        Returns:
-            NDArray[np.float32]: VAD output with shape (batch_size, num_samples
+            NDArray[np.float32]: VAD output with shape (batch_size, num_samples)
src/glados/engine.py (1)

501-501: Document the audio normalization logic.

While adding normalization is good, please add a comment explaining:

  1. Why division by max absolute value is used
  2. Why the additional division by 2 is necessary
-        audio = audio/np.max(np.abs(audio))/2  # Normalize audio
+        # Normalize audio to [-0.5, 0.5] range to prevent clipping and ensure consistent levels
+        audio = audio/np.max(np.abs(audio))/2
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 438d3ab and a621cb2.

📒 Files selected for processing (4)
  • src/glados/cli.py (2 hunks)
  • src/glados/core/asr.py (1 hunks)
  • src/glados/core/vad.py (2 hunks)
  • src/glados/engine.py (5 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/glados/core/asr.py
🔇 Additional comments (8)
src/glados/core/vad.py (3)

Line range hint 13-33: Well-documented initialization with proper provider handling.

The initialization changes look good:

  • Improved docstring with clear parameter descriptions
  • Proper handling of TensorRT provider
  • Streamlined parameter list

36-47: Clean state management implementation.

Good implementation of state management:

  • Clear type hints for state variables
  • Proper initialization in reset_states
  • Good separation of concerns

105-134: Well-implemented audio processing with proper padding.

The audio_forward method is well implemented:

  • Proper error handling
  • Efficient batch processing
  • Good padding implementation
src/glados/cli.py (2)

25-25: Verify the accessibility of the new VAD model URL.

Please ensure that the URL is accessible and returns the correct file:

✅ Verification successful

The VAD model URL is properly configured and accessible

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the accessibility of the new VAD model URL

# Check if the URL is accessible and returns a 200 status code
curl -I "https://github.com/dnhkng/GlaDOS/releases/download/0.1/silero_vad_v5.onnx"

Length of output: 4719


16-16: Verify the checksum for the new VAD model.

Please ensure that the checksum matches the actual file:

✅ Verification successful

Checksum verification successful

The SHA-256 hash of the VAD model file matches the checksum in the code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the checksum of the new VAD model

# Download the model and verify its checksum
curl -L -o silero_vad_v5.onnx "https://github.com/dnhkng/GlaDOS/releases/download/0.1/silero_vad_v5.onnx"
echo "6b99cbfd39246b6706f98ec13c7c50c6b299181f2474fa05cbc8046acc274396 silero_vad_v5.onnx" | sha256sum -c -

Length of output: 712


Script:

#!/bin/bash
# Use Python to compute SHA-256 hash
python3 -c '
import hashlib
import sys

def sha256sum(filename):
    h = hashlib.sha256()
    with open(filename, "rb") as f:
        for block in iter(lambda: f.read(4096), b""):
            h.update(block)
    return h.hexdigest()

expected = "6b99cbfd39246b6706f98ec13c7c50c6b299181f2474fa05cbc8046acc274396"
actual = sha256sum("silero_vad_v5.onnx")
print(f"Expected: {expected}")
print(f"Actual:   {actual}")
print(f"Match:    {expected == actual}")
'

Length of output: 622

src/glados/engine.py (3)

33-36: Validate the impact of VAD parameter changes.

The VAD parameters have been significantly adjusted:

  • VAD_SIZE: 50ms → 32ms (faster processing)
  • VAD_THRESHOLD: 0.9 → 0.8 (more lenient detection)
  • BUFFER_SIZE: 600ms → 800ms (larger buffer)
  • PAUSE_LIMIT: 500ms → 640ms (longer pause allowed)

Please validate that these changes:

  1. Don't negatively impact detection accuracy
  2. Don't increase false positives with the lower threshold
  3. Don't cause memory issues with the larger buffer

53-60: Well-documented method with clear return type and exceptions.

The docstring improvements look good:

  • Clear return type specification
  • Proper documentation of exceptions

236-240: Clean update to use new VAD model interface.

The audio callback changes look good:

  • Properly uses the new VAD model call method
  • Correct handling of audio data with np.expand_dims

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/glados/core/tts_kokoro.py (1)

69-69: Fix line length to comply with PEP 8.

The line exceeds the maximum length of 120 characters.

-        _letters_ipa = "ɑɐɒæɓʙβɔɕçɗɖðʤəɘɚɛɜɝɞɟʄɡɠɢʛɦɧħɥʜɨɪʝɭɬɫɮʟɱɯɰŋɳɲɴøɵɸθœɶʘɹɺɾɻʀʁɽʂʃʈʧʉʊʋⱱʌɣɤʍχʎʏʑʐʒʔʡʕʢǀǁǂǃˈˌːˑʼʴʰʱʲʷˠˤ˞↓↑→↗↘'̩'ᵻ"
+        _letters_ipa = (
+            "ɑɐɒæɓʙβɔɕçɗɖðʤəɘɚɛɜɝɞɟʄɡɠɢʛɦɧħɥʜɨɪʝɭɬɫɮʟɱɯɰŋɳɲɴøɵɸθœɶʘɹɺɾɻʀʁɽʂʃʈʧʉʊʋⱱʌɣɤʍχʎʏʑʐʒʔʡʕʢǀǁǂǃˈˌːˑʼʴʰʱʲʷˠˤ˞"
+            "↓↑→↗↘'̩'ᵻ"
+        )
🧰 Tools
🪛 Ruff (0.8.2)

69-69: Line too long (133 > 120)

(E501)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a621cb2 and 64d0ca1.

📒 Files selected for processing (7)
  • src/glados/cli.py (2 hunks)
  • src/glados/core/asr.py (2 hunks)
  • src/glados/core/phonemizer.py (1 hunks)
  • src/glados/core/tts_glados.py (1 hunks)
  • src/glados/core/tts_kokoro.py (3 hunks)
  • src/glados/core/vad.py (2 hunks)
  • src/glados/engine.py (8 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/glados/core/tts_glados.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/glados/core/asr.py
  • src/glados/cli.py
🧰 Additional context used
🪛 Ruff (0.8.2)
src/glados/core/tts_kokoro.py

69-69: Line too long (133 > 120)

(E501)

🔇 Additional comments (13)
src/glados/core/tts_kokoro.py (2)

1-1: LGTM! Good addition of pathlib import.

The addition of pathlib import aligns with Python best practices for path handling.


13-14: LGTM! Consistent path handling implementation.

Converting string literals to Path objects improves path handling consistency and cross-platform compatibility.

src/glados/core/phonemizer.py (1)

21-24: LGTM! Consistent path handling in ModelConfig.

The conversion of path strings to Path objects in ModelConfig improves path handling consistency and cross-platform compatibility.

src/glados/core/vad.py (6)

1-2: LGTM! Good addition of pathlib import.

The addition of pathlib import aligns with Python best practices for path handling.


10-10: LGTM! Consistent path handling for VAD_MODEL.

Converting the model path to a Path object improves consistency with the rest of the codebase.


Line range hint 15-43: LGTM! Improved VAD class initialization.

The refactored initialization is more robust with:

  • Better type hints
  • Cleaner state management
  • Improved docstring

45-49: LGTM! Clear state management with reset_states method.

Good implementation of state management with explicit initialization of all state variables.


51-104: LGTM! Well-implemented audio processing with robust error handling.

The __call__ method includes:

  • Comprehensive input validation
  • Clear error messages
  • Efficient state management
  • Proper type hints and docstrings

107-136: LGTM! Improved audio_forward method with better error handling.

The refactored method includes:

  • Clear docstring
  • Proper padding handling
  • Efficient batch processing
src/glados/engine.py (4)

33-36: Verify the impact of modified VAD constants.

The changes to VAD constants could affect voice detection sensitivity and responsiveness:

  • VAD_SIZE decreased from 50ms to 32ms
  • VAD_THRESHOLD decreased from 0.9 to 0.8
  • BUFFER_SIZE increased from 600ms to 800ms
  • PAUSE_LIMIT increased from 500ms to 640ms

Please test these values with different speech patterns and environments to ensure optimal performance.


54-61: LGTM! Improved docstring for PersonalityPrompt.to_chat_message.

The enhanced docstring clearly specifies:

  • Return type
  • Potential exceptions

238-240: LGTM! Updated VAD processing with new model interface.

The change from process_chunk to __call__ aligns with the VAD class refactor.


504-506: LGTM! Added audio normalization for better transcription.

Good addition of audio normalization to prevent clipping and ensure consistent levels.

@dnhkng dnhkng merged commit b8b66a7 into main Jan 30, 2025
@dnhkng dnhkng deleted the silero-5 branch January 30, 2025 19:51
baarratia pushed a commit to baarratia/GLaDOS that referenced this pull request Jul 5, 2025
* Update to Silero VAD 5

* Use Path instead of strings for files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant