A package to calculate SNR from audio files
Project description
Signal to Noise Ratio Calculation -
A Python package for calculating the Signal-to-Noise Ratio (SNR) of audio files. It supports processing individual audio files or all audio files within a directory and allows users to specify the frequency range of the signal.
Table of Contents
Features
- Calculate SNR for individual audio files or for all files in a directory.
- Supports custom signal frequency ranges and sample rates.
- Handles common audio formats like WAV, MP3, and FLAC.
Installation
-
Clone the repository or download the package.
-
Navigate to the package directory and run:
pip install .
Alternatively, if the package is available on PyPI, you can install it directly using:
pip install snr_calc
Usage
Calculating SNR for a Single File
from snr_package.snr_calc import process_audio_file
# Specify the path to the audio file
audio_file_path = "path/to/your/audio_file.wav"
# Calculate SNR with a custom signal frequency range and sample rate
snr_value = process_audio_file(audio_file_path, signal_freq_range=(500, 4000), sample_rate=None)
# Display the SNR result
if snr_value is not None:
print(f"SNR for {audio_file_path}: {snr_value} dB")
else:
print("Failed to calculate SNR.")
Calculating SNR for All Files in a Directory
from snr_package.snr_calc import process_directory
# Specify the path to the directory
directory_path = "path/to/your/audio_directory"
# Calculate SNR for all audio files in the directory
snr_results = process_directory(directory_path, signal_freq_range=(500, 4000), sample_rate=None)
# Display the SNR results for each file
if snr_results:
for file_name, snr_value in snr_results.items():
print(f"File: {file_name}, SNR: {snr_value} dB")
else:
print("No audio files found or failed to calculate SNR.")
Requirements
- Python 3.10 or higher
- Required Python packages:
- librosa
- numpy
- scipy
These dependencies are automatically installed when you install the package via pip.
Contributing
Contributions are welcome! If you want to contribute to the development of this package:
- Fork the repository.
- Create a new branch (git checkout -b feature/YourFeature).
- Commit your changes (git commit -am 'Add new feature').
- Push to the branch (git push origin feature/YourFeature).
- Create a Pull Request.
Please ensure your code passes all existing tests and add new tests if necessary.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Explanation
- Overview: Gives a brief description of the package and its purpose.
- Table of Contents: Provides easy navigation within the README.
- Features: Highlights key features of the package.
- Installation: Details how to install the package.
- Usage: Includes code snippets to demonstrate how to use the package for single files and directories.
- Requirements: Lists package dependencies.
- Contributing: Offers guidelines for developers who want to contribute to the package.
- License: States the license under which the package is distributed. Adjust it as needed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snr_calc-0.1.1.tar.gz.
File metadata
- Download URL: snr_calc-0.1.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
689295d3b1d2c7e21288c578407da3dac26a2f2d1f235c2b72b273257a2d7cf6
|
|
| MD5 |
c38badbe781badde8113390ba06e2366
|
|
| BLAKE2b-256 |
04a3930e22296a8da46bc9830d8a00a94ee2ab49cf62db8490a4675d06086a45
|
File details
Details for the file snr_calc-0.1.1-py3-none-any.whl.
File metadata
- Download URL: snr_calc-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
943215de891b6b4e46ace07d554ab3ffecadd57ca61b6b467c204de84ed8334f
|
|
| MD5 |
3cd9b4501cc892009c250cd2e969f102
|
|
| BLAKE2b-256 |
f3004f7e5744565f88f915ef277fcb78056849562bd5fa5fdec58ec02185f905
|