Skip to content

Conversation

luoling8192
Copy link
Member

@luoling8192 luoling8192 commented Jul 6, 2025

depends #3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @luoling8192, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Whisper API by providing explicit control over Voice Activity Detection (VAD) and improving its robustness. It also centralizes Hugging Face API configuration, making model loading more flexible and environment-aware. These changes aim to offer greater control to users and improve the reliability of audio transcription.

Highlights

  • Voice Activity Detection (VAD) Control: Introduced the ability to disable VAD entirely via the DISABLE_VAD environment variable. When disabled, the entire audio input is processed directly by the Whisper model, bypassing VAD segmentation for both complete and streaming transcriptions.
  • Improved VAD Robustness and Configuration: Implemented a fallback mechanism for VAD, ensuring that if no speech segments are detected, the entire audio is still processed. The default VAD threshold was lowered from 0.3 to 0.15, and AudioBuffer parameters were adjusted (min_speech from 100ms to 50ms, min_silence from 500ms to 300ms) for more lenient speech detection. VAD processing statistics are now logged to the console.
  • Centralized Hugging Face API Configuration: Added a new huggingface.rs module with a helper function (create_hf_api) to centralize the configuration of the Hugging Face API. This allows setting the API endpoint via HF_MIRROR and the cache directory via HF_HOME environment variables, which is now consistently used by both VAD and Whisper model loading.
  • Documentation Update: The README.md has been updated to include instructions for the new DISABLE_VAD and VAD_THRESHOLD environment variables, providing clear guidance for users on how to configure these options.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a feature to disable Voice Activity Detection (VAD) via the DISABLE_VAD environment variable, allowing for direct processing of entire audio files. This is implemented for both streaming and non-streaming transcription endpoints.

Comment on lines +329 to +340
// Fallback: If no segments were detected by VAD, process the entire audio
if transcripts.is_empty() && !audio_data.is_empty() {
println!("⚠️ No VAD segments detected, processing entire audio as fallback");
let whisper_start = Instant::now();
let transcript = whisper.transcribe(&audio_data)?;
let whisper_fallback_time = whisper_start.elapsed();
processing_stats.whisper_transcription_duration += whisper_fallback_time;

if !transcript.trim().is_empty() && !transcript.contains("[BLANK_AUDIO]") {
transcripts.push(transcript.trim().to_string());
}
}

Choose a reason for hiding this comment

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

high

The streaming function create_transcription_stream is missing a similar fallback. If no speech segments are detected during streaming, the stream will just complete without sending any transcription, which can be confusing for the user. This is an inconsistency between the two transcription modes.

Please consider adding a similar fallback mechanism to the streaming implementation. For example, you could check at the end of the stream if any segments were transcribed, and if not, transcribe the whole audio and send it as a final event.

Comment on lines +54 to +56
let vad_enabled = std::env::var("DISABLE_VAD")
.map(|s| s.to_lowercase() != "true" && s != "1")
.unwrap_or(true);

Choose a reason for hiding this comment

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

medium

The logic to determine if VAD is enabled is a bit hard to follow due to the negative condition (!=) combined with the DISABLE_VAD environment variable. It can be made more readable by checking for the "disabled" case first and then negating the result.

Suggested change
let vad_enabled = std::env::var("DISABLE_VAD")
.map(|s| s.to_lowercase() != "true" && s != "1")
.unwrap_or(true);
let vad_enabled = !std::env::var("DISABLE_VAD")
.map(|s| matches!(s.to_lowercase().as_str(), "true" | "1"))
.unwrap_or(false);

}
}

println!("🎯 VAD Stats: {speech_frame_count}/{total_frame_count} frames detected as speech ({:.1}%)", speech_frame_count as f32 / total_frame_count as f32 * 100.0);

Choose a reason for hiding this comment

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

medium

If audio_data is empty, total_frame_count will be 0, leading to a division by zero, which results in NaN for floating-point numbers. While this doesn't crash the program, it will print "NaN%", which is not ideal. It would be better to guard this print statement to avoid this.

Suggested change
println!("🎯 VAD Stats: {speech_frame_count}/{total_frame_count} frames detected as speech ({:.1}%)", speech_frame_count as f32 / total_frame_count as f32 * 100.0);
if total_frame_count > 0 {
println!("🎯 VAD Stats: {speech_frame_count}/{total_frame_count} frames detected as speech ({:.1}%)", speech_frame_count as f32 / total_frame_count as f32 * 100.0);
}

@luoling8192 luoling8192 marked this pull request as draft July 6, 2025 08:09
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