Giter Site home page Giter Site logo

jasminsternkopf / mel_cepstral_distance Goto Github PK

View Code? Open in Web Editor NEW
41.0 1.0 10.0 1.97 MB

Computes the Mel-Cepstral Distance of two WAV files based on the paper "Mel-Cepstral Distance Measure for Objective Speech Quality Assessment" by Robert F. Kubichek.

License: MIT License

Python 100.00%
mel-cepstral-distance mel speech-quality

mel_cepstral_distance's Introduction

Mel-Cepstral Distance

PyPI PyPI MIT PyPI PyPI DOI

CLI and library to compute the mel-cepstral distance of two WAV files based on the paper "Mel-Cepstral Distance Measure for Objective Speech Quality Assessment" by Robert F. Kubichek.

Installation

pip install mel-cepstral-distance --user

Usage as CLI

mcd-cli

Example

# Download two example audio files
wget https://github.com/jasminsternkopf/mel_cepstral_distance/raw/main/examples/similar_audios/original.wav
wget https://github.com/jasminsternkopf/mel_cepstral_distance/raw/main/examples/similar_audios/inferred.wav

# Calculate metrics
mcd-cli from-wav original.wav inferred.wav

Output:

Mel-Cepstral Distance: 19.013673608495836
Penalty: 0.11946050096339111
# Frames: 519

This will print a message informing you about the mel-cepstral distance and penalty between the audios whose paths were given as arguments and the number of frames that were used in the computation.

Usage as a library

from mel_cepstral_distance import get_metrics_wavs, get_metrics_mels, get_metrics_mels_pairwise

Main methods

  • get_metrics_wavs
  • get_metrics_mels

Both methods return the mel-cepstral distance, the penalty and the final frame number. Examples and information on the parameters can be found in the corresponding documentations.

Development setup

# update
sudo apt update
# install Python 3.8-3.11 for ensuring that tests can be run
sudo apt install python3-pip \
  python3.8 python3.8-dev python3.8-distutils python3.8-venv \
  python3.9 python3.9-dev python3.9-distutils python3.9-venv \
  python3.10 python3.10-dev python3.10-distutils python3.10-venv \
  python3.11 python3.11-dev python3.11-distutils python3.11-venv
# install pipenv for creation of virtual environments
python3.8 -m pip install pipenv --user

# check out repo
git clone https://github.com/jasminsternkopf/mel_cepstral_distance.git
cd mel_cepstral_distance
# create virtual environment
python3.8 -m pipenv install --dev

Running the tests

# first, install the tool (see "Development setup")
# then, navigate into the directory of the repo
cd mel_cepstral_distance
# activate environment
python3.8 -m pipenv shell
# run tests
tox

License

MIT License

References

  • Kubichek, R. “Mel-Cepstral Distance Measure for Objective Speech Quality Assessment.” In Proceedings of IEEE Pacific Rim Conference on Communications Computers and Signal Processing, 1:125–28. Victoria, BC, Canada: IEEE, 1993. https://doi.org/10.1109/PACRIM.1993.407206.
  • Muda, Lindasalwa, Mumtaj Begam, and I. Elamvazuthi. “Voice Recognition Algorithms Using Mel Frequency Cepstral Coefficient (MFCC) and Dynamic Time Warping (DTW) Techniques.” Journal of Computing vol. 2, no. 3 (March 2010): 6.

Acknowledgments

Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) – Project-ID 416228727 – CRC 1410

Citation

If you want to cite this repo, you can use the BibTeX-entry generated by GitHub (see About => Cite this repository).

Sternkopf, J., & Taubert, S. (2024). mel-cepstral-distance (Version 0.0.3) [Computer software]. https://doi.org/10.5281/zenodo.10567255

FAQ

How were the default parameters set?

We based some of the parameters on the two mentioned references and set the other ones by ourselves depending on the parameter description of the underlying libraries:

Why is Python 3.12 not supported?

The dependency numba is currently not available for Python 3.12.

mel_cepstral_distance's People

Contributors

jasminsternkopf avatar stefantaubert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mel_cepstral_distance's Issues

Default Arguments

Thanks for the MCD implementation!

I tried to run the get_mcd_between_wav_files function with the three sets of example provided and got MCD around 8-14.
Could you please tell how the default arguments are set (e.g. based on some documents, etc.)?
since if I change the arguments, the result MCD change quite a lot,
e.g. if I change the argument n_mels to, like 40, the MCD would be around double.

Also I get the following message with I fill the path to .wav files in wav_file_1 and wav_file_2 arguments.
C:\...\mcd\mcd_computation.py:318: FutureWarning: Pass y=[...] as keyword args. From version 0.10 passing these as positional arguments will result in an error
Could this warning be avoid?

Failing tests on MacOS

Hello!
Thanks for the implementation :) I followed the steps provided in the README, but the tests fail. I tested it on MacOS Monterey using Python=3.8 in a conda environment. It seems to me, that the problem concerns floating point precision. I tested it additionally using Ubuntu 18.04 and the issue does not happen there.

Here's the stack trace of the failed tests:

========================================== FAILURES ===========================================
_______________________ test_mcd_pen_frames_of_similar_audios_with_dtw ________________________

    def test_mcd_pen_frames_of_similar_audios_with_dtw():
      mcd, pen, frames = get_metrics_wavs(SIM_ORIG, SIM_INF, use_dtw=True)
    
>     assert mcd == 8.613918026817169
E     assert 8.613918026207012 == 8.613918026817169

src/mel_cepstral_distance_tests/test_examples.py:26: AssertionError
___________________ test_mcd_pen_frames_of_somewhat_similar_audios_with_dtw ___________________

    def test_mcd_pen_frames_of_somewhat_similar_audios_with_dtw():
      mcd, pen, frames = get_metrics_wavs(SOSIM_ORIG, SOSIM_INF, use_dtw=True)
    
>     assert mcd == 9.62103176737408
E     assert 9.621031769396891 == 9.62103176737408

src/mel_cepstral_distance_tests/test_examples.py:34: AssertionError
______________________ test_mcd_pen_frames_of_dissimilar_audios_with_dtw ______________________

    def test_mcd_pen_frames_of_dissimilar_audios_with_dtw():
      mcd, pen, frames = get_metrics_wavs(DISSIM_ORIG, DISSIM_INF, use_dtw=True)
    
>     assert mcd == 13.983229820898327
E     assert 13.983229825697364 == 13.983229820898327

src/mel_cepstral_distance_tests/test_examples.py:42: AssertionError
______________________ test_mcd_pen_frames_of_similar_audios_without_dtw ______________________

    def test_mcd_pen_frames_of_similar_audios_without_dtw():
      mcd, pen, frames = get_metrics_wavs(SIM_ORIG, SIM_INF, use_dtw=False)
    
>     assert mcd == 19.526543043605322
E     assert 19.526543040998817 == 19.526543043605322

src/mel_cepstral_distance_tests/test_examples.py:58: AssertionError
_________________ test_mcd_pen_frames_of_somewhat_similar_audios_without_dtw __________________

    def test_mcd_pen_frames_of_somewhat_similar_audios_without_dtw():
      mcd, pen, frames = get_metrics_wavs(SOSIM_ORIG, SOSIM_INF, use_dtw=False)
    
>     assert mcd == 21.97334780846056
E     assert 21.973347810693944 == 21.97334780846056

src/mel_cepstral_distance_tests/test_examples.py:66: AssertionError
____________________ test_mcd_pen_frames_of_dissimilar_audios_without_dtw _____________________

    def test_mcd_pen_frames_of_dissimilar_audios_without_dtw():
      mcd, pen, frames = get_metrics_wavs(DISSIM_ORIG, DISSIM_INF, use_dtw=False)
    
>     assert mcd == 19.473360173721225
E     assert 19.47336017064123 == 19.473360173721225

src/mel_cepstral_distance_tests/test_examples.py:74: AssertionError

Error in wav file path

Thank you for providing this library,

I am having issue loading the path and it throws attribute error

Exception has occurred: AttributeError
'str' object has no attribute 'shape'
File "C:\laryngectomy\scripts\evaluation_2_metric.py", line 13, in
mcd = get_metrics_mels(wave1, wave2, n_mfcc=40)
AttributeError: 'str' object has no attribute 'shape'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.