Audio-Similarity


NameAudio-Similarity JSON
Version 1.0 PyPI version JSON
download
home_pagehttps://github.com/markstent/audio-similarity
SummaryAudio similarity metrics for audio tasks
upload_time2023-06-05 14:16:57
maintainer
docs_urlNone
authorMark Stent
requires_python>=3.9
licenseMIT
keywords audio similarity audio similarity swass stent
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Audio Similarity Package

## Table of Contents

- [Audio Similarity Package](#audio-similarity-package)
  - [Key Features](#key-features)
  - [Installation](#installation)
  - [Usage Example](#usage-example)
  - [Metrics](#metrics)
    - [Stent Weighted Audio Similarity](#stent-weighted-audio-similarity)
    - [Zero Crossing Rate (ZCR) Similarity](#zero-crossing-rate-zcr-similarity)
    - [Rhythm Similarity](#rhythm-similarity)
    - [Chroma Similarity](#chroma-similarity)
    - [Energy Envelope Similarity](#energy-envelope-similarity)
    - [Spectral Contrast Similarity](#spectral-contrast-similarity)
    - [Perceptual Similarity](#perceptual-similarity)
  - [Plotting](#plotting)
  - [License](#license)
  - [Contributing](#contributing)
  - [Acknowledgements](#acknowledgements)
  - [Contact](#contact)
  - [Bugs and future work](#Bugs-and-future-work)



The Audio Similarity Package is a Python library that provides functionalities to measure and compare the similarity between audio signals. It offers various metrics to evaluate different aspects of audio similarity, allowing users to assess the resemblance between original audio and generated audio, or between different audio samples.

Whether you are working on audio analysis, music generation, speech recognition, or any application that requires audio comparison, this package can be a valuable tool in quantifying and understanding the degree of similarity between audio signals.

## Key Features

-   Calculation of various audio similarity metrics:
    -   Zero Crossing Rate (ZCR) Similarity
    -   Rhythm Similarity
    -   Chroma Similarity
    -   Energy Envelope Similarity
    -   Spectral Contrast Similarity
    -   Perceptual Similarity
    -   Stent Weighted Audio Similarity
-   Customizable weights for the Stent Weighted Audio Similarity metric
-   Visualization of audio similarity metrics through spider plots and horizontal bar plots
-   Easy-to-use interface for loading and comparing audio files
 
## Installation

You can install the Audio Similarity package using pip. Open your terminal or command prompt and run the following command:

```bash
pip install audio-similarity
```

This will download and install the latest version of the package from the Python Package Index (PyPI) along with its dependencies.

Alternatively, you can install a specific version of the package by specifying the version number. For example, to install version 1.0.0, you can use the following command:

```bash
pip install audio-similarity==1.0.0
```

Once the installation is complete, you can import the package in your Python code and start using it:

```python
from audio_similarity import AudioSimilarity

# Rest of your code...
```

Make sure you have Python and pip installed on your system before running the installation command.

That's it! You have successfully installed the Audio Similarity package using pip. You are now ready to use it for audio similarity analysis.

## Usage Example

Here's a simple example to demonstrate how to calculate the Stent Weighted Audio Similarity using the Audio Similarity Package:

```python
from audio_similarity import AudioSimilarity

# Paths to the original and compariosn audio files/folders

original_path = 'path/to/audio_folder'
compare_path = 'path/to/compare_audio.wav'

# Set the sample rate and weights for the metrics

sample_rate = 44100
weights = {
    'zcr_similarity': 0.2,
    'rhythm_similarity': 0.2,
    'chroma_similarity': 0.2,
    'energy_envelope_similarity': 0.1,
    'spectral_contrast_similarity': 0.1,
    'perceptual_similarity': 0.2
}

sample_size = 20 # If you have a large number of audio files, its much faster to select a randome sample from each

verbose = True # Show logs

# Create an instance of the AudioSimilarity class

audio_similarity = AudioSimilarity(original_path, compare_path, sample_rate, weights, verbose=verbose, sample_size=sample_size)

# Calculate a single metric

zcr_similarity = audio_similarity.zcr_similarity()

# Calculate the Stent Weighted Audio Similarity

similarity_score = audio_similarity.stent_weighted_audio_similarity(metrics='all') # You can select all metrics or just the 'swass' metric

print(f"Stent Weighted Audio Similarity: {similarity_score}")
```

This example demonstrates the calculation of the Stent Weighted Audio Similarity (SWASS) using a set of predefined weights for each metric. You can customize the weights to reflect your specific requirements and preferences.

## Metrics

The following metrics are available in the Audio Similarity package:

### Stent Weighted Audio Similarity

The stent weighted audio similarity is a powerful composite metric that combines multiple individual metrics using user-defined weights. It offers a flexible approach to customize the importance of each metric based on specific requirements, allowing users to tailor the similarity calculation to their specific needs.

The stent weighted audio similarity metric enables you to consider different aspects of audio similarity simultaneously and assign relative weights to each aspect based on their importance. This approach acknowledges that different metrics capture distinct characteristics of audio signals and allows you to emphasize certain aspects over others when calculating the overall similarity score.

Here's how the stent weighted audio similarity is calculated:

1. Individual Metric Calculation: Each individual metric, including ZCR similarity, rhythm similarity, chroma similarity, energy envelope similarity, spectral contrast similarity, and perceptual similarity, is calculated between the original audio and the generated audio. These metrics capture different aspects of the audio signals, such as temporal patterns, pitch content, energy variations, spectral characteristics, and perceptual quality.

2. Weight Assignment: User-defined weights are assigned to each metric. These weights determine the relative importance of each metric in the overall similarity score. The weights should be non-negative and sum up to 1. Adjusting the weights allows you to prioritize certain metrics according to your specific application or preference. For example, if preserving rhythm accuracy is crucial, you can assign a higher weight to the rhythm similarity metric.

3. Weighted Score Calculation: The individual metric scores are multiplied by their respective weights. This step scales each metric's contribution to the overall similarity score based on the assigned weight.

4. Overall Similarity Calculation: The weighted scores from all metrics are summed to obtain the stent weighted audio similarity score. The resulting score represents the overall similarity between the original audio and the generated audio, considering the weighted contributions of each metric.

The stent weighted audio similarity score ranges from 0 to 1, with a value of 1 indicating maximum similarity. By adjusting the weights assigned to each metric, you can effectively control the influence of different aspects of audio similarity on the final score.

To use the stent weighted audio similarity metric, follow these steps:

1. Instantiate an instance of the `AudioSimilarity` class, providing the necessary parameters such as the paths to the original and generated audio files, the sample rate, and optional weights.

2. Set the desired weights for each metric using the `weights` parameter. If weights are not provided, default weights are used, evenly distributed among the metrics.

3. Call the `stent_weighted_audio_similarity` method to calculate the overall similarity score. This method internally calculates the individual metrics and combines them according to the assigned weights.

Here's an example usage of the stent weighted audio similarity metric:

```python
from audio_similarity import AudioSimilarity

original_path = '/path/to/folder/or/file'
generated_path = '/path/to/folder/or/file'

# Instantiate the AudioSimilarity class
audio_similarity = AudioSimilarity(original_path, generated_path, sample_rate, weights)

# Calculate the stent weighted audio similarity
similarity_score = audio_similarity.stent_weighted_audio_similarity()

print(f"Stent Weighted Audio Similarity: {similarity_score}")
```

The stent weighted audio similarity metric provides a comprehensive measure of similarity that can be customized to specific applications or preferences. By adjusting the weights assigned to each metric, you can prioritize different aspects of audio similarity, enabling more fine-grained analysis and evaluation of audio generation or transformation tasks.

### Zero Crossing Rate (ZCR) Similarity

Zero Crossing Rate (ZCR) Similarity is a metric that quantifies the similarity between the zero crossing rates of the original audio and the generated audio signals. The zero crossing rate is the rate at which the audio waveform crosses the horizontal axis (zero amplitude) and changes its polarity (from positive to negative or vice versa). The ZCR can provide insights into the temporal characteristics and overall shape of the audio signal.

The ZCR similarity ranges from 0 to 1, where a value of 1 indicates a perfect match between the zero crossing rates of the two audio signals. A higher ZCR similarity score suggests that the original and generated audio signals have similar patterns of changes in amplitude and share comparable temporal characteristics.

    zcr_similarity = audio_similarity.zcr_similarity()

### Rhythm Similarity

Rhythm Similarity is a metric that evaluates the similarity between the rhythmic patterns of the original audio and the generated audio signals. It focuses on the presence and timing of onsets, which are abrupt changes or transients in the audio waveform that often correspond to beats or rhythmic events.

The rhythm similarity score ranges from 0 to 1, with a value of 1 indicating a perfect match between the rhythmic patterns of the two audio signals. A higher rhythm similarity score suggests that the original and generated audio exhibit similar rhythmic structures, including the timing and occurrence of onsets.

While rhythm similarity provides valuable insights into the rhythmic patterns of audio signals, it should be complemented with other metrics and contextual information for a comprehensive assessment of audio similarity. Additionally, variations in rhythmic interpretation or different musical genres may influence the perception of rhythm similarity, requiring domain-specific considerations.

    rhythm_similarity = audio_similarity.rhythm_similarity()

### Chroma Similarity

Chroma Similarity is a metric that quantifies the similarity between the pitch content of the original audio and the generated audio. It focuses on the distribution of pitches and their relationships within an octave, disregarding the octave's absolute frequency. The chroma representation is a 12-dimensional feature vector that captures the presence or absence of each pitch class (e.g., C, C#, D, D#, etc.) in the audio signal.

The chroma similarity score ranges from 0 to 1, with a value of 1 indicating a perfect match in terms of pitch content. A higher chroma similarity score suggests that the original and generated audio exhibit similar pitch distributions, reflecting similarities in tonality, chord progressions, or melodic patterns.

It's important to note that chroma similarity focuses solely on pitch content and does not consider other aspects of audio, such as timbre or rhythm. Therefore, it is recommended to combine chroma similarity with other metrics and contextual information for a more comprehensive evaluation of audio similarity, especially in cases where timbral or rhythmic differences may influence the overall perception of similarity.

    chroma_similarity= audio_similarity.chroma_similarity()

### Energy Envelope Similarity

The energy envelope similarity is a metric that quantifies the similarity between the energy envelopes of the original audio and the generated audio. The energy envelope represents the magnitude variations of the audio signal over time, capturing the overall energy profile of the audio.

The energy envelope similarity score ranges from 0 to 1, with a value of 1 indicating a perfect match in terms of energy envelope. A higher energy envelope similarity score suggests that the original and generated audio exhibit similar energy variations over time, indicating similarities in dynamics, intensity, or loudness.

It's important to note that energy envelope similarity primarily focuses on the overall energy variations and does not capture detailed spectral or temporal features of the audio signal. Therefore, it is recommended to combine energy envelope similarity with other metrics and perceptual evaluations to obtain a more comprehensive understanding of audio similarity, especially in cases where timbral or temporal differences may impact the perceived similarity.

    energy_envelope_similarity = audio_similarity.energy_envelope_similarity()

### Spectral Contrast Similarity

  The spectral contrast similarity is a metric that quantifies the similarity between the spectral contrast features of the original audio and the generated audio. Spectral contrast measures the difference in magnitude between peaks and valleys in the audio spectrum, providing information about the spectral richness and emphasis of different frequency regions.

The spectral contrast similarity score ranges from 0 to 1, with a value of 1 indicating a perfect match in terms of spectral contrast. A higher spectral contrast similarity score suggests that the original and generated audio exhibit similar patterns of spectral emphasis and richness, indicating similarities in the distribution of energy across different frequency bands.

It's important to note that spectral contrast similarity primarily focuses on the spectral richness and emphasis patterns and may not capture other aspects of audio similarity, such as temporal dynamics or pitch content. Therefore, it is recommended to combine spectral contrast similarity with other metrics and perceptual evaluations to obtain a more comprehensive understanding of audio similarity, especially in cases where temporal or melodic differences may impact the perceived similarity.

    spectral_contrast_similarity = audio_similarity.spectral_contrast_similarity()

### Perceptual Similarity

The perceptual similarity metric quantifies the perceptual similarity between the original audio and the generated audio. It leverages the Short-Time Objective Intelligibility (STOI) algorithm, which is designed to estimate the perceptual quality and intelligibility of speech signals.

The perceptual similarity score ranges from 0 to 1, with a value of 1 indicating perfect perceptual similarity. A higher perceptual similarity score suggests that the generated audio closely matches the perceptual quality of the original audio, indicating a high level of similarity in terms of perceived speech intelligibility and quality.

It's important to note that perceptual similarity is primarily focused on speech signals and may not fully capture the perceptual similarity for other types of audio, such as music or environmental sounds. Therefore, it is recommended to consider other audio similarity metrics and perceptual evaluations tailored to specific audio content when assessing similarity outside of speech signals.

    perceptual_similarity = audio_similarity.perceptual_similarity()

## Plotting

The `plot` method allows you to create a spider plot or a horizontal bar plot to visualize the audio similarity metrics.

#### Parameters

- `metrics`: A list of metrics to plot. These metrics represent the audio similarity measures that will be visualized.
- `option`: Option to specify the plot type. Use `'spider'` for a spider plot or `'bar'` for a horizontal bar plot or `all` for both.
- `figsize`: Figure size in inches, specified as a tuple of `(width, height)`.
- `color1`: Color(s) of the bar plot
- `color2`: Color(s) of the radar plot
- `alpha`: Transparency level(s) of the plot. Specify a single alpha value as a float or a list of alpha values for each metric.
- `title`: Title of the plot.
- `dpi`: Dots Per Inch, for the quality of the plot
- `savefig`: Save the plot to the current directory.
- `fontsize`: Font size for the plot.
- `label_fontsize`: Font size for the plot labels.
- `title_fontsize`: Font size of the title of the plot.

#### Usage Examples

To create a spider and radar plot on one image:

```python
audio_similarity.plot(metrics=None,
                      option='all',
                      figsize=(10, 7),
                      color1='red',
                      color2='green',
                      dpi=100,
                      savefig=False,
                      fontsize=6,
                      label_fontsize=8,
                      title_fontsize=14, 
                      alpha=0.5, 
                      title='Audio Similarity Metrics')
```
![plot](images/plot-all.png)

To create a horizontal bar plot: 

Make sure to replace `audio_similarity` with the appropriate instance of the `AudioSimilarity` class.


## License

The Audio Similarity Package is licensed under the MIT License. Please see the [LICENSE](https://github.com/markstent/audio-similarity/blob/main/LICENSE) file for more information.

## Contributing

Contributions to the Audio Similarity Package are welcome! If you encounter any issues, have suggestions, or would like to contribute enhancements or new features, please feel free to submit a pull request or open an issue in the [GitHub repository](https://github.com/markstent/audio-similarity).

We appreciate your feedback and contributions in making the Audio Similarity Package even better!

## Acknowledgements

We would like to acknowledge the open-source libraries and tools that have made the Audio Similarity Package possible, including [Librosa](https://librosa.org/), [NumPy](https://numpy.org/), [Matplotlib](https://matplotlib.org/), and [Pystoi](https://github.com/mpariente/pystoi).

Special thanks to the developers and contributors of these projects for their valuable work.

## Contact

Email: mark@markstent.co.za
Linkdin: https://www.linkedin.com/in/markstent/
Medium: https://medium.com/@markstent

## Bugs and future work

- Annoying warnings on some MP3 files need to be removed.
- Very slow, needs to speed up calculating metrics


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/markstent/audio-similarity",
    "name": "Audio-Similarity",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "audio,similarity,audio similarity,swass,stent",
    "author": "Mark Stent",
    "author_email": "mark@markstent.co.za",
    "download_url": "https://files.pythonhosted.org/packages/b0/aa/3df86c54ab717c53e3b794b43eebd2e4f740fc6a83f93811f9f5e20d1477/Audio%20Similarity-1.0.tar.gz",
    "platform": null,
    "description": "\ufeff\n# Audio Similarity Package\n\n## Table of Contents\n\n- [Audio Similarity Package](#audio-similarity-package)\n  - [Key Features](#key-features)\n  - [Installation](#installation)\n  - [Usage Example](#usage-example)\n  - [Metrics](#metrics)\n    - [Stent Weighted Audio Similarity](#stent-weighted-audio-similarity)\n    - [Zero Crossing Rate (ZCR) Similarity](#zero-crossing-rate-zcr-similarity)\n    - [Rhythm Similarity](#rhythm-similarity)\n    - [Chroma Similarity](#chroma-similarity)\n    - [Energy Envelope Similarity](#energy-envelope-similarity)\n    - [Spectral Contrast Similarity](#spectral-contrast-similarity)\n    - [Perceptual Similarity](#perceptual-similarity)\n  - [Plotting](#plotting)\n  - [License](#license)\n  - [Contributing](#contributing)\n  - [Acknowledgements](#acknowledgements)\n  - [Contact](#contact)\n  - [Bugs and future work](#Bugs-and-future-work)\n\n\n\nThe Audio Similarity Package is a Python library that provides functionalities to measure and compare the similarity between audio signals. It offers various metrics to evaluate different aspects of audio similarity, allowing users to assess the resemblance between original audio and generated audio, or between different audio samples.\n\nWhether you are working on audio analysis, music generation, speech recognition, or any application that requires audio comparison, this package can be a valuable tool in quantifying and understanding the degree of similarity between audio signals.\n\n## Key Features\n\n-   Calculation of various audio similarity metrics:\n    -   Zero Crossing Rate (ZCR) Similarity\n    -   Rhythm Similarity\n    -   Chroma Similarity\n    -   Energy Envelope Similarity\n    -   Spectral Contrast Similarity\n    -   Perceptual Similarity\n    -   Stent Weighted Audio Similarity\n-   Customizable weights for the Stent Weighted Audio Similarity metric\n-   Visualization of audio similarity metrics through spider plots and horizontal bar plots\n-   Easy-to-use interface for loading and comparing audio files\n \n## Installation\n\nYou can install the Audio Similarity package using pip. Open your terminal or command prompt and run the following command:\n\n```bash\npip install audio-similarity\n```\n\nThis will download and install the latest version of the package from the Python Package Index (PyPI) along with its dependencies.\n\nAlternatively, you can install a specific version of the package by specifying the version number. For example, to install version 1.0.0, you can use the following command:\n\n```bash\npip install audio-similarity==1.0.0\n```\n\nOnce the installation is complete, you can import the package in your Python code and start using it:\n\n```python\nfrom audio_similarity import AudioSimilarity\n\n# Rest of your code...\n```\n\nMake sure you have Python and pip installed on your system before running the installation command.\n\nThat's it! You have successfully installed the Audio Similarity package using pip. You are now ready to use it for audio similarity analysis.\n\n## Usage Example\n\nHere's a simple example to demonstrate how to calculate the Stent Weighted Audio Similarity using the Audio Similarity Package:\n\n```python\nfrom audio_similarity import AudioSimilarity\n\n# Paths to the original and compariosn audio files/folders\n\noriginal_path = 'path/to/audio_folder'\ncompare_path = 'path/to/compare_audio.wav'\n\n# Set the sample rate and weights for the metrics\n\nsample_rate = 44100\nweights = {\n    'zcr_similarity': 0.2,\n    'rhythm_similarity': 0.2,\n    'chroma_similarity': 0.2,\n    'energy_envelope_similarity': 0.1,\n    'spectral_contrast_similarity': 0.1,\n    'perceptual_similarity': 0.2\n}\n\nsample_size = 20 # If you have a large number of audio files, its much faster to select a randome sample from each\n\nverbose = True # Show logs\n\n# Create an instance of the AudioSimilarity class\n\naudio_similarity = AudioSimilarity(original_path, compare_path, sample_rate, weights, verbose=verbose, sample_size=sample_size)\n\n# Calculate a single metric\n\nzcr_similarity = audio_similarity.zcr_similarity()\n\n# Calculate the Stent Weighted Audio Similarity\n\nsimilarity_score = audio_similarity.stent_weighted_audio_similarity(metrics='all') # You can select all metrics or just the 'swass' metric\n\nprint(f\"Stent Weighted Audio Similarity: {similarity_score}\")\n```\n\nThis example demonstrates the calculation of the Stent Weighted Audio Similarity (SWASS) using a set of predefined weights for each metric. You can customize the weights to reflect your specific requirements and preferences.\n\n## Metrics\n\nThe following metrics are available in the Audio Similarity package:\n\n### Stent Weighted Audio Similarity\n\nThe stent weighted audio similarity is a powerful composite metric that combines multiple individual metrics using user-defined weights. It offers a flexible approach to customize the importance of each metric based on specific requirements, allowing users to tailor the similarity calculation to their specific needs.\n\nThe stent weighted audio similarity metric enables you to consider different aspects of audio similarity simultaneously and assign relative weights to each aspect based on their importance. This approach acknowledges that different metrics capture distinct characteristics of audio signals and allows you to emphasize certain aspects over others when calculating the overall similarity score.\n\nHere's how the stent weighted audio similarity is calculated:\n\n1. Individual Metric Calculation: Each individual metric, including ZCR similarity, rhythm similarity, chroma similarity, energy envelope similarity, spectral contrast similarity, and perceptual similarity, is calculated between the original audio and the generated audio. These metrics capture different aspects of the audio signals, such as temporal patterns, pitch content, energy variations, spectral characteristics, and perceptual quality.\n\n2. Weight Assignment: User-defined weights are assigned to each metric. These weights determine the relative importance of each metric in the overall similarity score. The weights should be non-negative and sum up to 1. Adjusting the weights allows you to prioritize certain metrics according to your specific application or preference. For example, if preserving rhythm accuracy is crucial, you can assign a higher weight to the rhythm similarity metric.\n\n3. Weighted Score Calculation: The individual metric scores are multiplied by their respective weights. This step scales each metric's contribution to the overall similarity score based on the assigned weight.\n\n4. Overall Similarity Calculation: The weighted scores from all metrics are summed to obtain the stent weighted audio similarity score. The resulting score represents the overall similarity between the original audio and the generated audio, considering the weighted contributions of each metric.\n\nThe stent weighted audio similarity score ranges from 0 to 1, with a value of 1 indicating maximum similarity. By adjusting the weights assigned to each metric, you can effectively control the influence of different aspects of audio similarity on the final score.\n\nTo use the stent weighted audio similarity metric, follow these steps:\n\n1. Instantiate an instance of the `AudioSimilarity` class, providing the necessary parameters such as the paths to the original and generated audio files, the sample rate, and optional weights.\n\n2. Set the desired weights for each metric using the `weights` parameter. If weights are not provided, default weights are used, evenly distributed among the metrics.\n\n3. Call the `stent_weighted_audio_similarity` method to calculate the overall similarity score. This method internally calculates the individual metrics and combines them according to the assigned weights.\n\nHere's an example usage of the stent weighted audio similarity metric:\n\n```python\nfrom audio_similarity import AudioSimilarity\n\noriginal_path = '/path/to/folder/or/file'\ngenerated_path = '/path/to/folder/or/file'\n\n# Instantiate the AudioSimilarity class\naudio_similarity = AudioSimilarity(original_path, generated_path, sample_rate, weights)\n\n# Calculate the stent weighted audio similarity\nsimilarity_score = audio_similarity.stent_weighted_audio_similarity()\n\nprint(f\"Stent Weighted Audio Similarity: {similarity_score}\")\n```\n\nThe stent weighted audio similarity metric provides a comprehensive measure of similarity that can be customized to specific applications or preferences. By adjusting the weights assigned to each metric, you can prioritize different aspects of audio similarity, enabling more fine-grained analysis and evaluation of audio generation or transformation tasks.\n\n### Zero Crossing Rate (ZCR) Similarity\n\nZero Crossing Rate (ZCR) Similarity is a metric that quantifies the similarity between the zero crossing rates of the original audio and the generated audio signals. The zero crossing rate is the rate at which the audio waveform crosses the horizontal axis (zero amplitude) and changes its polarity (from positive to negative or vice versa). The ZCR can provide insights into the temporal characteristics and overall shape of the audio signal.\n\nThe ZCR similarity ranges from 0 to 1, where a value of 1 indicates a perfect match between the zero crossing rates of the two audio signals. A higher ZCR similarity score suggests that the original and generated audio signals have similar patterns of changes in amplitude and share comparable temporal characteristics.\n\n    zcr_similarity = audio_similarity.zcr_similarity()\n\n### Rhythm Similarity\n\nRhythm Similarity is a metric that evaluates the similarity between the rhythmic patterns of the original audio and the generated audio signals. It focuses on the presence and timing of onsets, which are abrupt changes or transients in the audio waveform that often correspond to beats or rhythmic events.\n\nThe rhythm similarity score ranges from 0 to 1, with a value of 1 indicating a perfect match between the rhythmic patterns of the two audio signals. A higher rhythm similarity score suggests that the original and generated audio exhibit similar rhythmic structures, including the timing and occurrence of onsets.\n\nWhile rhythm similarity provides valuable insights into the rhythmic patterns of audio signals, it should be complemented with other metrics and contextual information for a comprehensive assessment of audio similarity. Additionally, variations in rhythmic interpretation or different musical genres may influence the perception of rhythm similarity, requiring domain-specific considerations.\n\n    rhythm_similarity = audio_similarity.rhythm_similarity()\n\n### Chroma Similarity\n\nChroma Similarity is a metric that quantifies the similarity between the pitch content of the original audio and the generated audio. It focuses on the distribution of pitches and their relationships within an octave, disregarding the octave's absolute frequency. The chroma representation is a 12-dimensional feature vector that captures the presence or absence of each pitch class (e.g., C, C#, D, D#, etc.) in the audio signal.\n\nThe chroma similarity score ranges from 0 to 1, with a value of 1 indicating a perfect match in terms of pitch content. A higher chroma similarity score suggests that the original and generated audio exhibit similar pitch distributions, reflecting similarities in tonality, chord progressions, or melodic patterns.\n\nIt's important to note that chroma similarity focuses solely on pitch content and does not consider other aspects of audio, such as timbre or rhythm. Therefore, it is recommended to combine chroma similarity with other metrics and contextual information for a more comprehensive evaluation of audio similarity, especially in cases where timbral or rhythmic differences may influence the overall perception of similarity.\n\n    chroma_similarity= audio_similarity.chroma_similarity()\n\n### Energy Envelope Similarity\n\nThe energy envelope similarity is a metric that quantifies the similarity between the energy envelopes of the original audio and the generated audio. The energy envelope represents the magnitude variations of the audio signal over time, capturing the overall energy profile of the audio.\n\nThe energy envelope similarity score ranges from 0 to 1, with a value of 1 indicating a perfect match in terms of energy envelope. A higher energy envelope similarity score suggests that the original and generated audio exhibit similar energy variations over time, indicating similarities in dynamics, intensity, or loudness.\n\nIt's important to note that energy envelope similarity primarily focuses on the overall energy variations and does not capture detailed spectral or temporal features of the audio signal. Therefore, it is recommended to combine energy envelope similarity with other metrics and perceptual evaluations to obtain a more comprehensive understanding of audio similarity, especially in cases where timbral or temporal differences may impact the perceived similarity.\n\n    energy_envelope_similarity = audio_similarity.energy_envelope_similarity()\n\n### Spectral Contrast Similarity\n\n  The spectral contrast similarity is a metric that quantifies the similarity between the spectral contrast features of the original audio and the generated audio. Spectral contrast measures the difference in magnitude between peaks and valleys in the audio spectrum, providing information about the spectral richness and emphasis of different frequency regions.\n\nThe spectral contrast similarity score ranges from 0 to 1, with a value of 1 indicating a perfect match in terms of spectral contrast. A higher spectral contrast similarity score suggests that the original and generated audio exhibit similar patterns of spectral emphasis and richness, indicating similarities in the distribution of energy across different frequency bands.\n\nIt's important to note that spectral contrast similarity primarily focuses on the spectral richness and emphasis patterns and may not capture other aspects of audio similarity, such as temporal dynamics or pitch content. Therefore, it is recommended to combine spectral contrast similarity with other metrics and perceptual evaluations to obtain a more comprehensive understanding of audio similarity, especially in cases where temporal or melodic differences may impact the perceived similarity.\n\n    spectral_contrast_similarity = audio_similarity.spectral_contrast_similarity()\n\n### Perceptual Similarity\n\nThe perceptual similarity metric quantifies the perceptual similarity between the original audio and the generated audio. It leverages the Short-Time Objective Intelligibility (STOI) algorithm, which is designed to estimate the perceptual quality and intelligibility of speech signals.\n\nThe perceptual similarity score ranges from 0 to 1, with a value of 1 indicating perfect perceptual similarity. A higher perceptual similarity score suggests that the generated audio closely matches the perceptual quality of the original audio, indicating a high level of similarity in terms of perceived speech intelligibility and quality.\n\nIt's important to note that perceptual similarity is primarily focused on speech signals and may not fully capture the perceptual similarity for other types of audio, such as music or environmental sounds. Therefore, it is recommended to consider other audio similarity metrics and perceptual evaluations tailored to specific audio content when assessing similarity outside of speech signals.\n\n    perceptual_similarity = audio_similarity.perceptual_similarity()\n\n## Plotting\n\nThe `plot` method allows you to create a spider plot or a horizontal bar plot to visualize the audio similarity metrics.\n\n#### Parameters\n\n- `metrics`: A list of metrics to plot. These metrics represent the audio similarity measures that will be visualized.\n- `option`: Option to specify the plot type. Use `'spider'` for a spider plot or `'bar'` for a horizontal bar plot or `all` for both.\n- `figsize`: Figure size in inches, specified as a tuple of `(width, height)`.\n- `color1`: Color(s) of the bar plot\n- `color2`: Color(s) of the radar plot\n- `alpha`: Transparency level(s) of the plot. Specify a single alpha value as a float or a list of alpha values for each metric.\n- `title`: Title of the plot.\n- `dpi`: Dots Per Inch, for the quality of the plot\n- `savefig`: Save the plot to the current directory.\n- `fontsize`: Font size for the plot.\n- `label_fontsize`: Font size for the plot labels.\n- `title_fontsize`: Font size of the title of the plot.\n\n#### Usage Examples\n\nTo create a spider and radar plot on one image:\n\n```python\naudio_similarity.plot(metrics=None,\n                      option='all',\n                      figsize=(10, 7),\n                      color1='red',\n                      color2='green',\n                      dpi=100,\n                      savefig=False,\n                      fontsize=6,\n                      label_fontsize=8,\n                      title_fontsize=14, \n                      alpha=0.5, \n                      title='Audio Similarity Metrics')\n```\n![plot](images/plot-all.png)\n\nTo create a horizontal bar plot: \n\nMake sure to replace `audio_similarity` with the appropriate instance of the `AudioSimilarity` class.\n\n\n## License\n\nThe Audio Similarity Package is licensed under the MIT License. Please see the [LICENSE](https://github.com/markstent/audio-similarity/blob/main/LICENSE) file for more information.\n\n## Contributing\n\nContributions to the Audio Similarity Package are welcome! If you encounter any issues, have suggestions, or would like to contribute enhancements or new features, please feel free to submit a pull request or open an issue in the [GitHub repository](https://github.com/markstent/audio-similarity).\n\nWe appreciate your feedback and contributions in making the Audio Similarity Package even better!\n\n## Acknowledgements\n\nWe would like to acknowledge the open-source libraries and tools that have made the Audio Similarity Package possible, including [Librosa](https://librosa.org/), [NumPy](https://numpy.org/), [Matplotlib](https://matplotlib.org/), and [Pystoi](https://github.com/mpariente/pystoi).\n\nSpecial thanks to the developers and contributors of these projects for their valuable work.\n\n## Contact\n\nEmail: mark@markstent.co.za\nLinkdin: https://www.linkedin.com/in/markstent/\nMedium: https://medium.com/@markstent\n\n## Bugs and future work\n\n- Annoying warnings on some MP3 files need to be removed.\n- Very slow, needs to speed up calculating metrics\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Audio similarity metrics for audio tasks",
    "version": "1.0",
    "project_urls": {
        "Download": "https://github.com/markstent/audio-similarity.git",
        "Homepage": "https://github.com/markstent/audio-similarity"
    },
    "split_keywords": [
        "audio",
        "similarity",
        "audio similarity",
        "swass",
        "stent"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3786648bc984fe3db0f8c632f7d943bd07da421794d8b61c5a96bf697727d2f",
                "md5": "4a9d5223e070d88541823f755b0744b3",
                "sha256": "aa05e980d1bccac039bcba81624f3e5509cbcd5b796f66167878a19cc8ad0560"
            },
            "downloads": -1,
            "filename": "Audio_Similarity-1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4a9d5223e070d88541823f755b0744b3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 13924,
            "upload_time": "2023-06-05T14:16:55",
            "upload_time_iso_8601": "2023-06-05T14:16:55.163325Z",
            "url": "https://files.pythonhosted.org/packages/d3/78/6648bc984fe3db0f8c632f7d943bd07da421794d8b61c5a96bf697727d2f/Audio_Similarity-1.0-py3-none-any.whl",
            "yanked": true,
            "yanked_reason": "text errors"
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0aa3df86c54ab717c53e3b794b43eebd2e4f740fc6a83f93811f9f5e20d1477",
                "md5": "4878742825bdb3cff90661d73633660b",
                "sha256": "ac2d50675b80eae42f8b7bd71676df5baa07cb0ebcda85ed289b776f61200454"
            },
            "downloads": -1,
            "filename": "Audio Similarity-1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4878742825bdb3cff90661d73633660b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 14116,
            "upload_time": "2023-06-05T14:16:57",
            "upload_time_iso_8601": "2023-06-05T14:16:57.332731Z",
            "url": "https://files.pythonhosted.org/packages/b0/aa/3df86c54ab717c53e3b794b43eebd2e4f740fc6a83f93811f9f5e20d1477/Audio%20Similarity-1.0.tar.gz",
            "yanked": true,
            "yanked_reason": "text errors"
        }
    ],
    "upload_time": "2023-06-05 14:16:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "markstent",
    "github_project": "audio-similarity",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "audio-similarity"
}
        
Elapsed time: 0.08444s