Perth
Perth is a comprehensive Python library for audio watermarking and detection.
Overview
Perth enables you to embed imperceptible watermarks in audio files and later detect them, even after the audio has undergone various transformations or manipulations. The library implements multiple watermarking techniques including neural network-based approaches.
Features
- Multiple Watermarking Techniques: Including the Perth-Net Implicit neural network approach
- Robust Watermarks: Watermarks can survive common audio transformations like compression, resampling, and more
- Command-Line Interface: Easy to use CLI for quick watermarking tasks
- Python API: Comprehensive API for integration into your applications
- Quality Metrics: Tools to evaluate the perceptual quality of watermarked audio
Installation
From PyPI (Recommended)
pip install resemble-perth
From Source
git clone https://github.com/resemble-ai/Perth
cd Perth
pip install -e .
Quick Start
Command Line Usage
# Apply a watermark to an audio file
perth input.wav -o output.wav
# Extract a watermark from an audio file
perth input.wav --extract
Python API Usage
Applying a Watermark
import perth
import librosa
import soundfile as sf
# Load audio file
wav, sr = librosa.load("input.wav", sr=None)
# Initialize watermarker
watermarker = perth.PerthImplicitWatermarker()
# Apply watermark
watermarked_audio = watermarker.apply_watermark(wav, watermark=None, sample_rate=sr)
# Save watermarked audio
sf.write("output.wav", watermarked_audio, sr)
Extracting a Watermark
import perth
import librosa
# Load the watermarked audio
watermarked_audio, sr = librosa.load("output.wav", sr=None)
# Initialize watermarker (same as used for embedding)
watermarker = perth.PerthImplicitWatermarker()
# Extract watermark
watermark = watermarker.get_watermark(watermarked_audio, sample_rate=sr)
print(f"Extracted watermark: {watermark}")
Perth Implicit Watermarker
The Perth-Net Implicit watermarker uses a neural network-based approach for embedding and extracting watermarks. It's designed to be robust against various audio manipulations while maintaining high audio quality.
from perth.perth_net.perth_net_implicit.perth_watermarker import PerthImplicitWatermarker
watermarker = PerthImplicitWatermarker(device="cuda") # Use GPU for faster processing
Dummy Watermarker
A simple placeholder watermarker for testing and demonstration purposes.
from perth import DummyWatermarker
watermarker = DummyWatermarker()
Evaluating Watermarked Audio
The library includes utilities for evaluating the quality and robustness of watermarked audio:
import librosa
from perth.utils import calculate_audio_metrics, plot_audio_comparison
# Load original and watermarked audio
original, sr = librosa.load("input.wav", sr=None)
watermarked, _ = librosa.load("output.wav", sr=None)
# Calculate quality metrics
metrics = calculate_audio_metrics(original, watermarked)
print(f"SNR: {metrics['snr']:.2f} dB")
print(f"PSNR: {metrics['psnr']:.2f} dB")
# Visualize differences
plot_audio_comparison(original, watermarked, sr, output_path="comparison.png")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for resemble-perth 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| resemble_perth-1.0.1.tar.gz | 34.4 MB | Without provenance | Details for resemble_perth-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| resemble_perth-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for resemble_perth-1.0.1-py3-none-any.whl |
Total release size: 68.8 MB
Release files / resemble_perth-1.0.1.tar.gz
| Download URL | resemble_perth-1.0.1.tar.gz |
|---|---|
| Size | 34.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4688cfc22e07b2ace567b987eb2c26e4ac19cbc37fbfacfd6794a2933ad2392
|
|
BLAKE2b-256 checksum How to use checksums |
d802f9b5adba306b5cd8bc5525f6bcad8f9d6840c6635d74fcf229a45c0dfb56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Release files / resemble_perth-1.0.1-py3-none-any.whl
| Download URL | resemble_perth-1.0.1-py3-none-any.whl |
|---|---|
| Size | 34.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65e9c37531b1a128a4a56226b75dece4521683cf3611b0b2a5ffe234f00c9342
|
|
BLAKE2b-256 checksum How to use checksums |
77cc73226dd776f8e9c2975f64f4efc22988fb37e5b185ba5cccd6f2e7196954
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Security for resemble-perth 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.