Skip to main content

Audio Watermarking and Detection Library

Project description

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 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

resemble_perth-1.0.0.tar.gz (34.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

resemble_perth-1.0.0-py3-none-any.whl (34.4 MB view details)

Uploaded Python 3

File details

Details for the file resemble_perth-1.0.0.tar.gz.

File metadata

  • Download URL: resemble_perth-1.0.0.tar.gz
  • Upload date:
  • Size: 34.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for resemble_perth-1.0.0.tar.gz
Algorithm Hash digest
SHA256 808e1e8a0e3f44d14751e9742b0094b8e6c8015e50025ecc9b4fdcf67baf09a4
MD5 5c24e780fe9e88b7fbb0e5e5ed82d962
BLAKE2b-256 3068af39fc34524fa0c582bbac10fc65df5713f7b00c0adae4a354b97ea1b11d

See more details on using hashes here.

File details

Details for the file resemble_perth-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: resemble_perth-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 34.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for resemble_perth-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7607b7fc4167f06fb0ce8e275c556dda3e272de5ae807120549bea579867af8f
MD5 2a212416fa91b2bd7bc78eb1a27f6c4d
BLAKE2b-256 653489516e67eeda837ceee1dbc091436e3755eecfb7cccff9299d89c64ee4ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page