from audioseal import AudioSeal# Load generator from model cardmodel = AudioSeal.load_generator("audioseal_wm_16bits")model.eval()# Alternative: Load from checkpoint path# model = AudioSeal.load_generator("/path/to/generator.pth", nbits=16)
Generate the watermark separately, then add it to your audio:
import torch# Load your audio as a tensor of shape (batch, channels, samples)# wav: torch.Tensor with shape [batch, channels, time]# Generate the watermarkwatermark = model.get_watermark(wav)# Add watermark to audiowatermarked_audio = wav + watermark
# Apply watermarking with default strength (alpha=1.0)watermarked_audio = model(wav, alpha=1.0)# Or use a different alpha valuewatermarked_audio = model(wav, alpha=0.8)
The alpha parameter controls watermark strength. Values between 0.5 and 1.5 are recommended. Higher values make the watermark more robust but potentially more audible.
# Returns detailed per-frame resultsresult, message = detector(watermarked_audio)# result shape: [batch, 2, frames]# result[:, 0, :] = probability of NO watermark# result[:, 1, :] = probability of watermark presentprint(result[:, 1, :]) # Watermark probability for each frameprint(message) # Decoded message (batch x 16 bits)
A watermarked audio should have result[:, 1, :] > 0.5 for most frames.
The alpha parameter lets you control the trade-off between robustness and audio quality:
1
Low Alpha (0.3 - 0.7)
More imperceptible watermark, but less robust to attacks. Good for high-quality audio where minimal distortion is critical.
2
Medium Alpha (0.8 - 1.2)
Balanced trade-off. Recommended for most use cases. Default value is 1.0.
3
High Alpha (1.3 - 1.5)
Maximum robustness against attacks like compression and noise, but potentially more audible. Use when audio may undergo heavy processing.
# Example: Adjust alpha based on use case# High quality music - use lower alphamusic_watermarked = model(music_audio, alpha=0.6)# Podcast that may be compressed - use defaultpodcast_watermarked = model(podcast_audio, alpha=1.0)# Audio for noisy environments - use higher alpha robust_watermarked = model(audio, alpha=1.3)