Brouhaha: Multi-task Audio Analysis Model

repository·main·Indexed 41 days ago

https://github.com/marianne-m/brouhaha-vad

A multi-task machine learning model for audio analysis specializing in Voice Activity Detection (VAD), Speech-to-Noise Ratio (SNR) estimation, and C50 room acoustics estimation. It includes a CLI for training (supporting simple and pyannet architectures), hyperparameter tuning via Optuna, inference, and performance scoring using F-score and Mean Squared Error (MSE).

Tokens
3.4K
Snippets
13
Records
16
Agent score
52%

What's inside Brouhaha

  1. Brouhaha model capabilities

    main

    Brouhaha is a multi-task model designed to extract three specific acoustic features from audio segments:

    • Speech/non-speech segments: Voice Activity Detection (VAD).
    • Speech-to-Noise Ratio (SNR): Measures the speech level relative to the noise level.
    • C50: Measures the extent of environmental reverberation.
  2. Train the Brouhaha model

    main

    Train the model using the train command. You must specify an experimental directory, a task profile (-p), a model type, the number of epochs, and the data directory.

    To use custom hyper-parameters and task parameters, place a config.yaml in your experimental directory and include the --config flag in your command.

    Example (Basic):

    python main.py train /path/to/experimental/directory \
        -p Brouhaha.SpeakerDiarization.NoisySpeakerDiarization \
        --model_type pyannet \
        --epoch 35 \
        --data_dir path/to/your/database

    Example (With config.yaml):

    python main.py train /path/to/experimental/directory \
        -p Brouhaha.SpeakerDiarization.NoisySpeakerDiarization \
        --model_type pyannet \
        --epoch 35 \
        --data_dir path/to/your/database \
        --config
    python main.py train /path/to/experimental/directory \
        -p Brouhaha.SpeakerDiarization.NoisySpeakerDiarization \
        --model_type pyannet \
        --epoch 35 \
        --data_dir path/to/your/database
  3. Install Brouhaha

    main

    To install Brouhaha, clone the repository, create a Conda environment with Python 3.8, and install the package using pip. Depending on your environment, you may also need to install libsndfile via conda-forge.

    # clone brouhaha
    git clone https://github.com/marianne-m/brouhaha-vad.git
    cd brouhaha-vad
    
    # creating a conda environment
    conda create -n brouhaha python=3.8
    conda activate brouhaha
    
    # install brouhaha
    pip install .
    
    # optional: install libsndfile if necessary
    conda install -c conda-forge libsndfile
  4. Configure the Brouhaha database structure and path

    main

    Your database must include a train/dev/test split. Each split must follow this specific directory structure:

    train/
    ├── audio_16k
    │   └── file_1.flac
    │   └── ...
    ├── detailed_snr_labels
    │   └── file_1_snr.npy
    │   └── ...
    ├── reverb_labels.txt
    └── rttm_files
        └── file_1.rttm
        └── ...

    To register the database, add a Brouhaha entry to your ~/.pyannote/database.yml file using the following pattern:

    Databases:
      Brouhaha: Path/to/your/database/*/audio_16k/{uri}.flac
    Databases:
      Brouhaha: Path/to/your/database/*/audio_16k/{uri}.flac
  5. Score the model performance

    main

    Use the score command to evaluate the model. This computes:

    • F-Score for Voice Activity Detection (VAD)
    • Mean Squared Error (MSE) for SNR
    • Mean Squared Error (MSE) for C50 room acoustics estimation.
    python main.py score \
        -p Brouhaha.SpeakerDiarization.NoisySpeakerDiarization \
        --model_path path/to/the/model/checkpoint \
        --data_dir path/to/your/database \
        --out_dir path/to/the/inference/output/folder \
        --report_path path/to/score/files
  6. Install the pyannote-brouhaha-db package

    main

    To loop through Brouhaha data, you must install the pyannote-brouhaha-db package. Ensure your conda environment is activated before installation.

    conda activate brouhaha
    pip install https://github.com/marianne-m/pyannote-brouhaha-db.git
    conda activate brouhaha
    pip install https://github.com/marianne-m/pyannote-brouhaha-db.git
  7. Apply the model for inference

    main

    Use the apply command to run inference on the test portion of your database.

    If --params is not specified, the system defaults to the parameters tuned on the Brouhaha database. Use --ext to specify the output file extension (e.g., wav).

    python main.py apply \
        -p Brouhaha.SpeakerDiarization.NoisySpeakerDiarization \
        --model_path path/to/the/model/checkpoint \
        --data_dir path/to/your/database \
        --out_dir path/to/the/inference/output/folder \
        --ext wav \
        --params path/to/best/params/yaml/file
  8. Analyze SNR and C50 on the CHiME5 dataset

    main

    This analysis uses the Brouhaha model to extract Signal-to-Noise Ratio (SNR) and C50 (reverberation strength) scores from the CHiME5 dataset. The goal is to investigate correlations between these acoustic metrics and the physical distance between a speaker and a microphone.

    Experimental Setup

    • Dataset: CHiME5 (specifically session S02).
    • Microphone Configuration: The experiment utilizes three types of microphone segments extracted for each utterance:
      1. Worn microphone: The microphone worn by the participant.
      2. Same room microphone: A stationary microphone located in the same room as the speaker.
      3. Different room microphone: A stationary microphone located in a different room from the speaker.
    • Metrics:
      • SNR: Predicted and averaged at the segment level.
      • C50: Predicted for each extracted segment.

    Key Findings

    • SNR: Higher SNR values correlate with closer proximity to the speaker.
    • C50: While microphones in the same or different rooms show similar C50 distributions, the worn microphone shows a distribution shifted towards higher C50 scores. Note that this distinction may be due to differences in microphone hardware types rather than speaker distance.
  9. Extract predictions from audio segments

    main

    Use the brouhaha/main.py script with the apply command to run the pretrained model on a directory of audio files. The model extracts Voice Activity Detection (speech/non-speech), Speech-to-Noise Ratio (SNR), and C50 reverberation metrics.

    python brouhaha/main.py apply \
          --data_dir path/to/data \
          --out_dir path/to/predictions \
          --model_path models/best/checkpoints/best.ckpt \
          --ext wav
  10. Tune the VAD threshold

    main

    After training, use the tune command to optimize the threshold for voice activity detection (VAD).

    If the --params flag is omitted, the best parameters will be automatically saved to best_params.yml within your experimental directory.

    python main.py tune /path/to/experimental/directory \
        -p Brouhaha.SpeakerDiarization.NoisySpeakerDiarization \
        --model_path path/to/the/model/checkpoint \
        --data_dir path/to/your/database \
        --params path/to/best/params/yaml/file
  11. Use the Brouhaha CLI to manage models

    main

    The Brouhaha project provides a command-line interface for four primary tasks: training models, tuning hyperparameters, applying models to data (inference), and scoring inference results against ground truth.

    Available commands:

    • train: Train a new model using a specified architecture and dataset.
    • tune: Optimize pipeline hyperparameters (like thresholds) using Optuna.
    • apply: Run inference on audio files to generate RTTM, SNR, and C50 predictions.
    • score: Evaluate the accuracy of previously generated inference results using metrics like F-score, MSE for SNR, and MSE for C50.
  12. Visualize gridsearch results with scattered boxplots

    main

    Use the scattered_boxplot function to visualize how different hyperparameters (like dropout, duration, batch_size, hidden_size, or num_layers) affect various performance metrics. The function generates a boxplot overlaid with jittered scatter points to show the distribution of results for each parameter value.

    Parameters

    • data: A pandas.DataFrame containing the gridsearch results.
    • param_to_monitor: The hyperparameter column name to plot on the x-axis.
    • metric: The performance metric column name (e.g., ValidationMetric, c50ValMetric, snrValMetric, vadValMetric).
    • dataset_name: One of "original", "dev", or "heldout". This determines the visual scaling (ratio, scattering, and widths) used for the plot.
    • figure_path: The file path where the plot will be saved.
    • save: Boolean indicating whether to save the figure.
    # Example: Plotting ValidationMetric against dropout for the heldout dataset
    scattered_boxplot(
        data_heldout_all, 
        param_to_monitor="dropout", 
        metric="ValidationMetric", 
        dataset_name="heldout", 
        save=True
    )