{"id":27966411,"url":"https://github.com/stefantaubert/mel-cepstral-distance","last_synced_at":"2025-07-28T21:08:57.762Z","repository":{"id":77474541,"uuid":"344115438","full_name":"stefantaubert/mel-cepstral-distance","owner":"stefantaubert","description":"A Python library for computing the Mel-Cepstral Distance (Mel-Cepstral Distortion, MCD) between two inputs. This implementation is based on the method proposed by Robert F. Kubichek in \"Mel-Cepstral Distance Measure for Objective Speech Quality Assessment\".","archived":false,"fork":false,"pushed_at":"2025-05-15T18:28:47.000Z","size":65779,"stargazers_count":55,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-28T08:14:33.394Z","etag":null,"topics":["cepstral","distance","distortion","divergence","dtw","dynamic-time-warping","language","linguistics","mcd","mel","mfcc","objective-evaluation","spectrogram","spectrum","speech-quality","speech-synthesis","text-to-speech","tts","voice-cloning"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefantaubert.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-03T12:15:33.000Z","updated_at":"2025-07-07T07:19:05.000Z","dependencies_parsed_at":"2024-01-24T17:53:36.223Z","dependency_job_id":"c1e93f1d-6769-4175-83e2-a8663b8997e0","html_url":"https://github.com/stefantaubert/mel-cepstral-distance","commit_stats":null,"previous_names":["stefantaubert/mel-cepstral-distance","jasminsternkopf/mel_cepstral_distance"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/stefantaubert/mel-cepstral-distance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefantaubert%2Fmel-cepstral-distance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefantaubert%2Fmel-cepstral-distance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefantaubert%2Fmel-cepstral-distance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefantaubert%2Fmel-cepstral-distance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefantaubert","download_url":"https://codeload.github.com/stefantaubert/mel-cepstral-distance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefantaubert%2Fmel-cepstral-distance/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267585808,"owners_count":24111577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cepstral","distance","distortion","divergence","dtw","dynamic-time-warping","language","linguistics","mcd","mel","mfcc","objective-evaluation","spectrogram","spectrum","speech-quality","speech-synthesis","text-to-speech","tts","voice-cloning"],"created_at":"2025-05-07T20:18:36.522Z","updated_at":"2025-07-28T21:08:57.753Z","avatar_url":"https://github.com/stefantaubert.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mel-cepstral-distance\n\n[![CI](https://github.com/stefantaubert/mel-cepstral-distance/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/stefantaubert/mel-cepstral-distance/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/github/stefantaubert/mel-cepstral-distance/branch/main/graph/badge.svg?token=DZ8LB2Q5I0)](https://codecov.io/github/stefantaubert/mel-cepstral-distance)\n[![PyPI](https://img.shields.io/pypi/v/mel-cepstral-distance.svg)](https://pypi.python.org/pypi/mel-cepstral-distance)\n[![PyPI](https://img.shields.io/pypi/pyversions/mel-cepstral-distance.svg)](https://pypi.python.org/pypi/mel-cepstral-distance)\n[![MIT](https://img.shields.io/github/license/stefantaubert/mel-cepstral-distance.svg)](https://github.com/stefantaubert/mel-cepstral-distance/blob/main/LICENSE)\n[![PyPI](https://img.shields.io/github/commits-since/stefantaubert/mel-cepstral-distance/latest/main.svg)](https://github.com/stefantaubert/mel-cepstral-distance/compare/v0.0.4...main)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/mel-cepstral-distance.svg?label=PyPI%20downloads)](https://pypi.org/project/mel-cepstral-distance)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.15213012.svg)](https://doi.org/10.5281/zenodo.15213012)\n\nA Python library for computing the Mel-Cepstral Distance (also known as Mel-Cepstral Distortion, MCD) between two inputs. This implementation is based on the method proposed by Robert F. Kubichek in [*Mel-Cepstral Distance Measure for Objective Speech Quality Assessment*](https://ieeexplore.ieee.org/document/407206).\n\n- Compute MCD between two inputs: audio files, amplitude spectrograms, Mel spectrograms, or MFCCs.\n- Calculate an alignment penalty (PEN) as an additional metric to indicate the extent of alignment applied.\n- Remove pauses from audio files or feature representations (amplitude spectrograms, Mel spectrograms, or MFCCs) using a threshold.\n- Align feature representations using either Dynamic Time Warping (DTW) or zero-padding.\n- Experimental results show a moderate negative correlation with naturalness (Spearman: –0.31) and a weak negative correlation with intelligibility (–0.24). For a detailed analysis of parameter configurations and their impact on correlation strength, see the [experiment report](https://github.com/stefantaubert/mel-cepstral-distance/blob/main/experiments/README.md).\n\n## Getting Started\n\n### Installation\n\n```sh\npip install mel-cepstral-distance\n```\n\n### Example usage\n\nCompare two audio files with default parameters:\n\n```py\nfrom mel_cepstral_distance import compare_audio_files\n\nmcd, penalty = compare_audio_files(\n  'examples/GT.wav',\n  'examples/Tacotron-2.wav',\n)\n\nprint(f'MCD: {mcd:.2f}, Penalty: {penalty:.4f}')\n# MCD: 7.45, Penalty: 0.1087\n```\n\n## Calculation\n\n### Spectrogram\n\n$$\nX(k, m) = \\text{FFT of } x_k(n), \\text{ for real input.}\n$$\n\nWhere:\n\n- $X(k, m)$: The result (amplitude spectrogram) of the real-valued FFT for the $k$-th frame at frequency index $m$.\n- $x_k(n)$: The time-domain signal of the $k$-th frame.\n- $\\text{FFT}$: The real-valued discrete Fourier transform, computed using `np.fft.rfft`.\n\n### Mel spectrogram\n\n$$\nX_{k,n} = \\log_{10}\\left\\lbrace\\sum_m^M |X(k, m)|^2 \\cdot w_n(m)\\right\\rbrace\n$$\n\nWhere:\n\n- $X_{k,n}$: The logarithmic Mel-scaled power spectrogram for the $k$-th frame at Mel frequency $n$.\n- $X(k, m)$: The amplitude spectrum of the $k$-th frame at frequency $m$.\n- $M$: The total number of Mel frequency bins.\n- $w_n(m)$: The Mel filter bank weights for Mel frequency $n$ and frequency bin $m$.\n\n### Mel-frequency cepstral coefficients\n\n$$\nMC_X(i, k) = \\sum_{n=1}^{M} X_{k,n} \\cos\\left[i\\left(n - \\frac{1}{2}\\right)\\frac{\\pi}{M}\\right]\n$$\n\nWhere:\n\n- $MC_X(i, k)$: The $i$-th Mel-frequency cepstral coefficient (MFCC) for the $k$-th frame.\n- $X_{k,n}$: The logarithmic Mel-scaled power spectrogram for the $k$-th frame at Mel frequency $n$.\n- $M$: The total number of Mel frequency bins.\n- $i$: The index of the MFCC being computed.\n\n### Mel-cepstral distance\n\n#### Per frame\n\n$$\nMCD(k) = \\alpha\\sqrt{\\sum_{i=s}^{D} \\left(MC_X(i, k) - MC_Y(i, k)\\right)^2}\n$$\n\nWhere:\n\n- $MCD(k)$: The Mel-cepstral distance for the $k$-th frame.\n- $MC_X(i, k)$: The $i$-th MFCC of the reference signal for the $k$-th frame.\n- $MC_Y(i, k)$: The $i$-th MFCC of the target signal for the $k$-th frame.\n- $D$: The number of MFCCs used in the computation.\n- $\\alpha$: Optional scaling factor used in some literature, e.g. $\\frac{10\\sqrt{2}}{\\ln 10}$.\n  - Note: Kubichek didn't use it, so it has value 1\n- $s$: Parameter to exclude the 0th coefficient (corresponding to energy):\n  - $s = 0$: Includes the 0th coefficient\n  - $s = 1$: Excludes the 0th coefficient\n\n#### Mean over all frames\n\n$$\nMCD = \\frac{1}{N} \\sum_{k=1}^{N} MCD(k)\n$$\n\nWhere:\n\n- $MCD$: The mean Mel-cepstral distance over all frames.\n- $N$: The total number of frames.\n- $MCD(k)$: The Mel-cepstral distance for the $k$-th frame.\n\n### Alignment penalty during Dynamic Time Warping (DTW)\n\n$$\nPEN = 2 - \\frac{N_X + N_Y}{N_{XY}}\n$$\n\nWhere:\n\n- $N_X$: The number of frames in the reference sequence.\n- $N_Y$: The number of frames in the target sequence.\n- $N_{XY}$: The number of frames after alignment (same for X and Y).\n- $PEN$: A value in interval $[0, 1)$, where a smaller value indicates less alignment.\n\n### Used parameters in literature\n\n| Literature | Sampling Rate | Window Size           | Hop Length           | FFT Size     | Window Function | $M$ | Min Frequency | Max Frequency | $s$ | $D$ | Pause | DTW | $\\alpha$                      | Smallest MCD | Largest MCD | Citation MCD | Domain  |\n| ---------- | ------------- | --------------------- | -------------------- | ------------ | --------------- | --- | ------------- | ------------- | --- | --- | ----- | --- | ----------------------------- | ------------ | ----------- | ------------ | ------- |\n| [1]        | 8kHz          | 32ms/256              | \u003c16ms/128*           | 32ms/256*    | ?               | 20  | 0Hz*          | 4kHz*         | 1   | 16  | no    | no  | 1                             | ~0.8         | ~1.05       | original     | generic |\n| [2]        | ?             | ?                     | ?                    | ?            | ?               | 80* | 80Hz*         | 12kHz*        | 1   | 13  | yes*  | no  | 1                             | 0.294        | 0.518       | [3]          | TTS     |\n| [3]        | 24kHz*        | ?                     | ?                    | ?            | ?               | 80  | 80Hz          | 12kHz         | 1   | 13  | yes*  | no  | 1                             | 6.99         | 12.37       | [1]          | TTS     |\n| [4]        | 16kHz*        | 25ms                  | 5ms                  | ?            | ?               | ?   | 0Hz*          | 8kHz*         | 1   | 24  | yes*  | no  | $\\frac{10}{\\ln(10)}$          | ~2.5dB       | ~12.5dB     | [5]          | TTS     |\n| [5]        | ?             | 30ms                  | 10ms                 | ?            | Hamming         | ?   | ?             | ?             | 1   | 10  | yes*  | yes | 1                             | 3.415        | 4.066       | [1]          | TTS     |\n| [6]        | ?             | \u003e10ms*                | 5ms                  | \u003e10ms*       | Gaussian*       | ?   | ?             | 8kHz*         | 1   | 24  | no    | no  | $\\frac{10 \\sqrt{2}}{\\ln(10)}$ | ~4.75        | ~6          | [7]          | VC      |\n| [7]        | 16kHz         | 40ms*                 | 5ms                  | 64ms/1024    | Gaussian        | ?   | ?             | 12kHz         | 1   | 40  | yes   | no  | $\\frac{10 \\sqrt{2}}{\\ln(10)}$ | 2.32dB       | 3.53dB      | none         | TTS     |\n| [8]        | 24kHz         | 50ms/1200             | 12.5ms/300           | 2048/~85.3ms | Hann            | 80  | 80Hz          | 12kHz         | 1   | 13  | yes*  | yes | 1                             | 4.83         | 5.68        | [1]          | TTS     |\n| [9]        | 16kHz         | 64ms/1024             | 16ms/256             | 128ms/2048   | Hann            | 80  | 125Hz         | 7.6kHz        | 1*  | 16* | yes*  | yes | 1*                            | 10.62        | 14.38       | [1]          | TTS     |\n| [10]       | 16kHz         | ?                     | ?                    | ?            | ?               | ?   | ?             | ?             | 1   | 16* | yes*  | yes | 1*                            | 8.67         | 19.41       | none         | TTS     |\n| [11]       | 16kHz*        | 64ms* (at 16kHz)/1024 | 16ms* (at 16kHz)/256 | 64ms*/1024*  | Hann*           | 80  | 0Hz           | 8kHz          | 1   | 60  | yes*  | no  | $\\frac{10 \\sqrt{2}}{\\ln(10)}$ | 5.32dB       | 6.78dB      | [12]         | TTS     |\n\n*Parameters are not explicitly stated, but were estimated from the information in the literature.\n  \n**Literature:**\n\n- [1] Kubichek, R. (1993). Mel-cepstral distance measure for objective speech quality assessment. Proceedings of IEEE Pacific Rim Conference on Communications Computers and Signal Processing, 1, 125–128. https://doi.org/10.1109/PACRIM.1993.407206 \n- [2] Lee, Y., \u0026 Kim, T. (2019). Robust and Fine-grained Prosody Control of End-to-end Speech Synthesis. ICASSP 2019 - 2019 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), 5911–5915. https://doi.org/10.1109/ICASSP.2019.8683501\n- [3] **Ref-Tacotron** -\u003e Skerry-Ryan, R. J., Battenberg, E., Xiao, Y., Wang, Y., Stanton, D., Shor, J., Weiss, R., Clark, R., \u0026 Saurous, R. A. (2018). Towards End-to-End Prosody Transfer for Expressive Speech Synthesis with Tacotron. Proceedings of the 35th International Conference on Machine Learning, 4693–4702. https://proceedings.mlr.press/v80/skerry-ryan18a.html\n- [4] Nature/ansp19-503 Anumanchipalli, G. K., Chartier, J., \u0026 Chang, E. F. (2019). Speech synthesis from neural decoding of spoken sentences. Nature, 568(7753), Article 7753. https://doi.org/10.1038/s41586-019-1119-1\n- [5] Shah, N. J., Vachhani, B. B., Sailor, H. B., \u0026 Patil, H. A. (2014). Effectiveness of PLP-based phonetic segmentation for speech synthesis. 2014 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), 270–274. https://doi.org/10.1109/ICASSP.2014.6853600\n- [6] Kominek, J., Schultz, T., \u0026 Black, A. W. (2008). Synthesizer voice quality of new languages calibrated with mean Mel cepstral distortion. SLTU, 63–68. http://www.cs.cmu.edu/~./awb/papers/sltu2008/kominek_black.sltu_2008.pdf\n- [7] Mashimo, M., Toda, T., Shikano, K., \u0026 Campbell, N. (2001). Evaluation of cross-language voice conversion based on GMM and straight. 7th European Conference on Speech Communication and Technology (Eurospeech 2001), 361–364. https://doi.org/10.21437/Eurospeech.2001-111\n- [8] **Capacitron** -\u003e Battenberg, E., Mariooryad, S., Stanton, D., Skerry-Ryan, R. J., Shannon, M., Kao, D., \u0026 Bagby, T. (2019). Effective Use of Variational Embedding Capacity in Expressive End-to-End Speech Synthesis (No. arXiv:1906.03402). arXiv. http://arxiv.org/abs/1906.03402\n- [9] **Attentron** -\u003e Choi, S., Han, S., Kim, D., \u0026 Ha, S. (2020). Attentron: Few-Shot Text-to-Speech Utilizing Attention-Based Variable-Length Embedding. Interspeech 2020, 2007–2011. https://doi.org/10.21437/Interspeech.2020-2096\n- [10] **VoiceLoop** -\u003e Taigman, Y., Wolf, L., Polyak, A., \u0026 Nachmani, E. (2018). VoiceLoop: Voice Fitting and Synthesis via a Phonological Loop. 6th International Conference on Learning Representations (ICLR 2018), 2, 1374–1387. https://openreview.net/forum?id=SkFAWax0-\n- [11] **MIST-Tacotron** -\u003e Moon, S., Kim, S., \u0026 Choi, Y.-H. (2022). MIST-Tacotron: End-to-End Emotional Speech Synthesis Using Mel-Spectrogram Image Style Transfer. IEEE Access, 10, 25455–25463. IEEE Access. https://doi.org/10.1109/ACCESS.2022.3156093\n- [12] Kim, J., Choi, H., Park, J., Hahn, M., Kim, S., \u0026 Kim, J.-J. (2018). Korean Singing Voice Synthesis Based on an LSTM Recurrent Neural Network. Interspeech 2018, 1551–1555. https://doi.org/10.21437/Interspeech.2018-1575\n\n### Default parameters\n\nBased on the values in the literature the default parameters were set:\n\n- Hop Length (hop_len): 8 ms\n  - Note: should be 1/2 or 1/4 of the window size\n- Window Size (win_len): 32 ms\n- FFT Size (n_fft): 32 ms\n  - For faster computation, the sample equivalent should be a power of 2.\n- Window Function (window): Hanning\n- Sampling Rate (sample_rate): is taken from the audio file\n- Minimum Frequency (fmin): 0 Hz\n- Maximum Frequency (fmax): sampling rate / 2\n  - Cannot exceed half the sampling rate.\n- Num. Mel-Bands ($M$): 20\n  - Increasing the number will increase the resulting MCD values.\n- $s$: 1\n- $D$: 16\n- $\\alpha$: 1 (alternate values can be applied by multiplying the MCD with a custom factor)\n- Aligning: DTW\n- Align Target (align_target): MFCC\n- Remove Silence: No\n  - Silence can be removed from Mel spectrograms before computing the MCD, with dataset-specific thresholds.\n\n### Suggested parameters\n\nBased on the conducted [experiments](https://github.com/stefantaubert/mel-cepstral-distance/blob/main/experiments/README.md), the following parameter settings are recommended to achieve the strongest correlation with subjective ratings:\n\n```\nsample_rate = 96000 Hz\nn_fft = 64 ms\nwin_len = 32 ms\nhop_len = 16 ms\nwindow = 'hanning'\nfmin = 0 Hz\nfmax = 48000 Hz\nM = 20\ns = 1\nD = 13\nalign_method = 'dtw'\nalign_target = 'mel'\nremove_silence = 'no'\nsilence_threshold_A = None\nsilence_threshold_B = None\nnorm_audio = True\ndtw_radius = 2\n```\n\nFurthermore, combining MCD and PEN using the formula `MCD*(PEN+1)` yield the strongest correlation with subjective ratings, according to the experimental results.\n\n**Note:** To enable meaningful cross-paper comparisons, it is strongly recommended that users of this library—whether adopting it directly or implementing their own version—explicitly report all parameter settings used for feature extraction and distance calculation, as inconsistent or undocumented configurations remain a major issue in the current literature.\n\n\n## License\n\nMIT License\n\n## Citation\n\nIf you want to cite this repo, you can use the BibTeX-entry generated by GitHub (see *About =\u003e Cite this repository*).\n\n```txt\nTaubert, S., \u0026 Sternkopf, J. (2025). mel-cepstral-distance (Version 0.0.4) [Computer software]. https://doi.org/10.5281/zenodo.15213012\n```\n\n## Acknowledgments\n\nFunded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) – Project-ID 416228727 – CRC 1410\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefantaubert%2Fmel-cepstral-distance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefantaubert%2Fmel-cepstral-distance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefantaubert%2Fmel-cepstral-distance/lists"}