ViSQOL: How to build and use on Windows
Tags: tutorial, acoustics
Published: 2023-10-02 13:09:50

## What is ViSQOL

> ViSQOL (Virtual Speech Quality Objective Listener) is an objective, full-reference metric for perceived audio quality. It uses a spectro-temporal measure of similarity between a reference and a test speech signal to produce a MOS-LQO (Mean Opinion Score - Listening Quality Objective) score. MOS-LQO scores range from 1 (the worst) to 5 (the best).

As the above citation from the [ViSQOL](https://github.com/google/visqol) README explains, ViSQOL is an objective metric for how good people feels the audio quality. There are many metrics for the similar purpose such as PESQ and POLQA, but the best point of ViSQOL is that it is an open source software and we can use it for free.

However, ViSQOL is mainly intended for using on Linux environment, and building it on Windows is not straightforward. As of now (Oct 2023), Windows build is "Experimental, last tested on Windows 10 x64, 2020 August" (ViSQOL README), and there is no official binary release for Windows. As far as I know, there is no article that explains in detail how to build ViSQOL on Windows. This is why I wrote this both for my personal memo and for anyone who wants to use ViSQOL on Windows.

## Software required for building ViSQOL (V3.3.3)

### Required softwares

- Bazel 5.4.0 (I also tried Bazel 6.1.0, but it failed to run unit tests)
- Python 3.9+ (I checked with 3.11 that is installed using the installer)
- Visual Studio 2022 (probably 2019 is OK)

The point here is that **you do NOT need MSYS2** to build ViSQOL. 

However, **you CANNOT use venv (or similar virtual environment for Python)**, as Bazel somehow fails to detect the right Python executables.

In addition, **I had to remove all other Python installations** to run the Bazel build script without errors.

### Recommended softwares

- Git (for fetching the source code)
- [Scoop](https://scoop.sh/) (for installing Git and Bazel)

Using Scoop, Bazel installation is easy: `scoop install bazel@5.4.0`.

## Preparation

1. Install required (and recommended) software. Make sure you have only one Python version (version 3.9+) installed.
2. Set `BAZEL_VC` environment variable to `C:\Program Files\Microsoft Visual Studio\2022\Community\VC` (change this if you installed Visual Studio in other directory or you installed a different version)
3. Execute the following to install the packages required to build TensorFlow

```
pip3 install -U six numpy wheel packaging
pip3 install -U keras_preprocessing --no-deps
```
4. Set Windows to developer mode to allow the script to create symbolic links.
5. Open "App execution aliases" settings and turn off aliases for Python as shown below.

![App execution aliases Python settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hiko90kygpxwp09szek7.png)

## Build

1. Clone the ViSQOL source code: `git clone https://github.com/google/visqol.git`
2. In the source directory, execute `bazel build :visqol -c opt`.
3. Execute `bazel test all_unit_tests` to perform unit tests.
4. Copy visqol.exe from the build directory (`bazel-out\x64_windows-opt\bin`). **No other file in the build directory is required for running ViSQOL**.
5. Copy "model" directory from the visqol source directory. **You need to put it in the current directory when executing `visqol.exe`**.

## How to use ViSQOL for Audio 

1. Prepare reference signals and degraded signals in WAV format (48kHz, 16bit). Exact time alignment is not required.
2. Put `visqol.exe` and "model" directory from the ViSQOL source directory in a working directory (or you can set PATH environment variable so you do not need to put `visqol.exe` to the working directory).
3. Execute `visqol --reference_file [file path to the reference signal] --degraded_file [file path to the degraded signal]` to get a single score.
4. For batch execution, prepare a CSV file with the following format:
```
reference,degraded
ref1.wav,deg1.wav
ref2.wav,deg2.wav
```
5. Execute `visqol --batch_input_csv [file path to the CSV file] --results_csv [file path to the output CSV]` to get a CSV file with the result for the batch execution:
```
reference,degraded,moslqo
ref1.wav,deg1.wav,3.4
ref2.wav,deg2.wav,4.1
```

## How to use ViSQOL for Speech

1. Prepare reference signals and degraded signals in WAV format (16kHz, 16bit). Exact time alignment is not required.
2. Put `visqol.exe` and "model" directory from the ViSQOL source directory in a working directory (or you can set PATH environment variable so you do not need to put `visqol.exe` to the working directory).
4. Execute `visqol --use_speech_mode --reference_file [file path to the reference signal] --degraded_file [file path to the degraded signal]` to get a single score.
5. For batch execution, prepare a CSV file with the following format:
```
reference,degraded
ref1.wav,deg1.wav
ref2.wav,deg2.wav
```
6. Execute `visqol --use_speech_mode --batch_input_csv [file path to the CSV file] --results_csv [file path to the output CSV]` to get a CSV file with the result for the batch execution:
```
reference,degraded,moslqo
ref1.wav,deg1.wav,3.4
ref2.wav,deg2.wav,4.1
```