Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Facebookresearch Audiocraft ViSQOL and SISNR

From Leeroopedia
Metadata
Knowledge Sources
Domains
Last Updated 2026-02-13 00:00 GMT

Overview

Concrete implementations of audio compression quality metrics within Audiocraft. The ViSQOL class wraps the external Google ViSQOL C++ binary to compute perceptual quality scores, while the SISNR class implements scale-invariant signal-to-noise ratio as a PyTorch module. Both are invoked during the evaluation stage of CompressionSolver.

Description

The ViSQOL wrapper prepares audio files in temporary directories, invokes the ViSQOL binary via subprocess, and parses the resulting CSV scores. It handles resampling to the target sample rate, optional silence padding, and batch processing of multiple audio pairs.

The SISNR module computes scale-invariant SNR on overlapping frames of audio, using a centered dot-product projection to separate target signal from noise. It returns the negated SI-SNR value so that it can also serve as a loss function during training.

Both metrics are wired into the evaluation pipeline through the evaluate_audio_reconstruction() function at the bottom of compression.py.

Usage

Import when computing audio quality metrics directly:

from audiocraft.metrics.visqol import ViSQOL
from audiocraft.losses.sisnr import SISNR

In practice, these are constructed by the builder functions builders.get_visqol() and builders.get_loss('sisnr', cfg) during evaluation.

Code Reference

Source Location

  • Repository: facebookresearch/audiocraft
  • File: audiocraft/metrics/visqol.py (lines 22--216)
  • File: audiocraft/losses/sisnr.py (lines 39--97)
  • Evaluation caller: audiocraft/solvers/compression.py, function evaluate_audio_reconstruction() at lines 320--328

Signature

class ViSQOL:
    """ViSQOL wrapper to run ViSQOL from Python using a pre-installed binary."""

    SAMPLE_RATES_MODES = {"audio": 48_000, "speech": 16_000}

    def __init__(
        self,
        bin: Union[Path, str],
        mode: str = "audio",
        model: str = "libsvm_nu_svr_model.txt",
        debug: bool = False,
    ):
        ...

    def __call__(
        self,
        ref_sig: torch.Tensor,    # [B, C, T]
        deg_sig: torch.Tensor,    # [B, C, T]
        sr: int,
        pad_with_silence: bool = False,
    ) -> float:
        """Return the mean ViSQOL MOS-LQO score for the batch."""
        ...


class SISNR(nn.Module):
    """SISNR loss. Returns negated SI-SNR (lower is better).

    Input should be [B, C, T], output is scalar.
    """

    def __init__(
        self,
        sample_rate: int = 16000,
        segment: Optional[float] = 20,
        overlap: float = 0.5,
        epsilon: float = torch.finfo(torch.float32).eps,
    ):
        ...

    def forward(
        self,
        out_sig: torch.Tensor,    # [B, C, T]
        ref_sig: torch.Tensor,    # [B, C, T]
    ) -> torch.Tensor:
        """Return negated SI-SNR scalar."""
        ...

Import

from audiocraft.metrics.visqol import ViSQOL
from audiocraft.losses.sisnr import SISNR

Dependencies

  • ViSQOL binary -- external C++ tool built with Bazel from https://github.com/google/visqol. Must be pre-installed and its path provided to the bin parameter.
  • torch -- tensor operations for SI-SNR computation
  • torchaudio -- resampling transforms for ViSQOL file preparation
  • subprocess -- for invoking the ViSQOL binary

I/O Contract

Inputs

Input Contract
Name Type Description
ref_sig (ViSQOL) torch.Tensor [B, C, T] Reference (original) audio signals.
deg_sig (ViSQOL) torch.Tensor [B, C, T] Degraded (reconstructed) audio signals.
sr (ViSQOL) int Sample rate of the input audio. Will be resampled to 48kHz (audio mode) or 16kHz (speech mode).
out_sig (SISNR) torch.Tensor [B, C, T] Reconstructed (predicted) audio signal.
ref_sig (SISNR) torch.Tensor [B, C, T] Reference (ground truth) audio signal. Must match shape of out_sig.

Outputs

Output Contract
Name Type Description
ViSQOL score float Mean MOS-LQO score across the batch, on a scale of 1.0 (very poor) to ~5.0 (excellent/transparent). Audio mode has a practical maximum of ~4.75.
SISNR value torch.Tensor (scalar) Negated SI-SNR in dB. More negative values indicate better reconstruction quality (since SI-SNR is negated). Typical good reconstruction: -20 to -30 dB (meaning actual SI-SNR of 20--30 dB).

Usage Examples

Example 1: Computing ViSQOL Score

Evaluating the perceptual quality of reconstructed audio using the ViSQOL wrapper.

from audiocraft.metrics.visqol import ViSQOL

visqol = ViSQOL(
    bin='/path/to/visqol',
    mode='audio',
    model='libsvm_nu_svr_model.txt',
)

# reference and degraded audio at 32kHz
# ref_audio, deg_audio: [B, 1, T]
score = visqol(ref_audio, deg_audio, sr=32000)
print(f"ViSQOL MOS-LQO: {score:.2f}")  # e.g., "ViSQOL MOS-LQO: 3.85"

Example 2: Computing SI-SNR

Measuring waveform-level reconstruction fidelity with SI-SNR.

from audiocraft.losses.sisnr import SISNR

sisnr = SISNR(sample_rate=32000, segment=20, overlap=0.5)

# out_audio: reconstructed, ref_audio: original, both [B, 1, T]
neg_sisnr = sisnr(out_audio, ref_audio)
print(f"SI-SNR: {-neg_sisnr.item():.1f} dB")  # e.g., "SI-SNR: 25.3 dB"

Example 3: Evaluation Pipeline in CompressionSolver

How both metrics are called together during evaluation (from evaluate_audio_reconstruction).

# From audiocraft/solvers/compression.py:
def evaluate_audio_reconstruction(y_pred, y, cfg):
    metrics = {}
    if cfg.evaluate.metrics.visqol:
        visqol = builders.get_visqol(cfg.metrics.visqol)
        metrics['visqol'] = visqol(y_pred, y, cfg.sample_rate)
    sisnr = builders.get_loss('sisnr', cfg)
    metrics['sisnr'] = sisnr(y_pred, y)
    return metrics

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment