Perth Audio Watermarking and Detection
resemble-perth is an audio watermarking and detection library developed by Resemble AI. It allows embedding and detecting imperceptible watermarks in audio signals, primarily designed for identifying AI-generated content. The current stable version is 1.0.1, with new releases typically occurring as features are added or bug fixes are made.
Common errors
-
ModuleNotFoundError: No module named 'resemble_perth'
cause The `resemble-perth` library is not installed in the current Python environment or the environment is not activated.fixRun `pip install resemble-perth` in your terminal. If using a virtual environment, ensure it is activated before running your script. -
TypeError: 'list' object cannot be interpreted as a numpy array
cause The input audio provided to `watermark` or `detect` is not a `numpy.ndarray`, but a different type like a list, tuple, or a PyTorch/TensorFlow tensor.fixConvert your audio data to a NumPy array (e.g., `np.array(your_audio_list)`). If loading from a file, use `librosa.load('audio.wav', sr=None)[0]` to get a 1D NumPy array of audio samples. -
ValueError: Audio sample rate X is not supported
cause The provided sample rate (X) for the audio is outside the supported range or not one of the recommended sample rates.fixResample your audio to a supported sample rate, ideally 44.1 kHz or 24 kHz, before passing it to the watermarker/detector. Example with `librosa`: `resampled_audio = librosa.resample(audio, orig_sr=X, target_sr=44100)`.
Warnings
- gotcha Optimal Performance with Specific Sample Rates
- gotcha Input Audio Must Be a NumPy Array
- gotcha CPU-bound Processing for Large Audio
Install
-
pip install resemble-perth
Imports
- Watermarker
from resemble_perth import Watermarker
- Detector
from resemble_perth import Detector
Quickstart
import librosa
import numpy as np
from resemble_perth import Watermarker, Detector
# Create a dummy audio signal (replace with your actual audio file)
sr = 44100 # Sample rate in Hz
duration = 3 # seconds
# A simple sine wave for demonstration
y = np.sin(2 * np.pi * 440 * np.linspace(0, duration, int(sr * duration))).astype(np.float32)
# Initialize Watermarker and watermark the audio
watermarker = Watermarker()
watermarked_audio = watermarker.watermark(y, sr)
print(f"Original audio shape: {y.shape}, sample rate: {sr}")
print(f"Watermarked audio shape: {watermarked_audio.shape}")
# Initialize Detector and detect watermark
detector = Detector()
is_watermarked = detector.detect(watermarked_audio, sr)
print(f"Is audio watermarked? {is_watermarked}")
# Example with a non-watermarked audio
non_watermarked_audio = np.random.randn(int(sr * duration)).astype(np.float32)
is_watermarked_false = detector.detect(non_watermarked_audio, sr)
print(f"Is non-watermarked audio detected as watermarked? {is_watermarked_false}")