CorentinJ/Real-Time-Voice-Cloning · error · ModuleNotFoundError

Package 'webrtcvad' not found. This package enables noise re

Error message

Package 'webrtcvad' not found. This package enables noise removal and is recommended. Please install and try again. If installation fails, use --no_trim to disable this error message.

What it means

Raised by encoder_preprocess.py when the webrtcvad import fails and --no_trim was not passed. webrtcvad powers trim_long_silences() (VAD-based silence removal) during encoder preprocessing; it is a recommended-but-optional C-extension package, and the script treats a missing install as a hard error unless trimming is explicitly disabled. Note the bare `except:` also swallows real import-time errors, not just absence of the package.

Source

Thrown at encoder_preprocess.py:49

        "defaults to <datasets_root>/SV2TTS/encoder/")
    parser.add_argument("-d", "--datasets", type=str,
                        default="librispeech_other,voxceleb1,voxceleb2", help=\
        "Comma-separated list of the name of the datasets you want to preprocess. Only the train "
        "set of these datasets will be used. Possible names: librispeech_other, voxceleb1, "
        "voxceleb2.")
    parser.add_argument("-s", "--skip_existing", action="store_true", help=\
        "Whether to skip existing output files with the same name. Useful if this script was "
        "interrupted.")
    parser.add_argument("--no_trim", action="store_true", help=\
        "Preprocess audio without trimming silences (not recommended).")
    args = parser.parse_args()

    # Verify webrtcvad is available
    if not args.no_trim:
        try:
            import webrtcvad
        except:
            raise ModuleNotFoundError("Package 'webrtcvad' not found. This package enables "
                "noise removal and is recommended. Please install and try again. If installation fails, "
                "use --no_trim to disable this error message.")
    del args.no_trim

    # Process the arguments
    args.datasets = args.datasets.split(",")
    if not hasattr(args, "out_dir"):
        args.out_dir = args.datasets_root.joinpath("SV2TTS", "encoder")
    assert args.datasets_root.exists()
    args.out_dir.mkdir(exist_ok=True, parents=True)

    # Preprocess the datasets
    print_args(args, parser)
    preprocess_func = {
        "librispeech_other": preprocess_librispeech,
        "voxceleb1": preprocess_voxceleb1,
        "voxceleb2": preprocess_voxceleb2,
    }

View on GitHub (pinned to 890f3a0318)

Solutions

  1. Install it in the environment you actually run the script with: `pip install webrtcvad` (or `pip install webrtcvad-wheels` for prebuilt wheels on newer Pythons), then re-run.
  2. Verify with `python -c "import webrtcvad"` using the same interpreter; if that fails with a build error, install a compiler toolchain or use webrtcvad-wheels.
  3. If you accept keeping silences, re-run with --no_trim to skip VAD trimming entirely (model quality may drop slightly).

Example fix

# before
python encoder_preprocess.py -d librispeech -i ~/datasets  # ModuleNotFoundError: webrtcvad

# after
pip install webrtcvad  # or: pip install webrtcvad-wheels
python encoder_preprocess.py -d librispeech -i ~/datasets
# fallback:
python encoder_preprocess.py -d librispeech -i ~/datasets --no_trim
Defensive patterns

Strategy: validation

Validate before calling

def webrtcvad_available() -> bool:
    try:
        import webrtcvad  # noqa: F401
        return True
    except Exception:
        return False

# before subprocess: assert webrtcvad_available() or pass "--no_trim"

Try / catch

try:
    subprocess.run([sys.executable, "encoder_preprocess.py", ...], check=True)
except subprocess.CalledProcessError:
    if not webrtcvad_available():
        subprocess.run([sys.executable, "encoder_preprocess.py", ..., "--no_trim"], check=True)
    else:
        raise

Prevention

When it happens

Trigger: Running `python encoder_preprocess.py` without --no_trim on an environment where `import webrtcvad` fails: package not installed, not in the active venv/uv environment, or its C extension fails to build/import on the current platform or Python version.

Common situations: New clone without requirements installed; using the wrong interpreter (system python vs the project venv); Python or OS upgrades breaking webrtcvad's wheel availability (e.g. new Python minor with no wheel); Windows/msvc or Alpine/musl environments where the C extension does not build.

Related errors


AI-assisted analysis of CorentinJ/Real-Time-Voice-Cloning@890f3a0318 (2026-08-15). Data as JSON: /api/errors/6455b3fcf1f6181d. Report an issue: GitHub.