Skip to main content

OfSpectrum Audio Watermarking SDK

Project description

OfSpectrum Python SDK

Official Python SDK for the OfSpectrum Audio Watermarking API.

Installation

pip install ofspectrum

Or install from source:

pip install -e /path/to/neo/sdk

Quick Start

from ofspectrum import OfSpectrum

# Initialize client with your API key
client = OfSpectrum(api_key="your_api_key")

# Create a watermark token (simple - uses "standard" type by default)
token = client.tokens.create(name="Production Token")
print(f"Created token: {token.id}")

# Or specify a type (creator/enterprise require public_key)
# token = client.tokens.create(
#     name="Creator Token",
#     token_type="creator",
#     public_key=12345
# )

# Encode watermark into audio
result = client.audio.encode(
    audio="input.mp3",
    token_id=token.id,
    output_path="watermarked.mp3"
)
print(f"Encoded {result.audio_duration}s of audio")

# Decode (detect) watermark from audio
decode = client.audio.decode("suspect.mp3")
if decode.watermarked:
    print(f"Watermark detected! Token ID: {decode.token_id}")
else:
    print("No watermark detected")

# Check your quota
quota = client.quotas.get_encode_quota()
print(f"Remaining encode quota: {quota.remaining}/{quota.quota_limit} seconds")

Features

Token Management

# List all tokens
tokens = client.tokens.list()

# Get a specific token
token = client.tokens.get("token-uuid")

# Update a token
token = client.tokens.update(
    token_id="token-uuid",
    name="New Name"
)

# Note: Token deletion is not available via API.
# Tokens are consumable resources.

Audio Watermarking

# Encode with custom settings
result = client.audio.encode(
    audio="input.mp3",
    token_id=token.id,
    strength=1.0,          # 0.1-2.0
    normalize=True,         # Smooth audio to reduce artifacts
    check_watermark=True,   # Check for existing watermark first
    output_path="output.mp3"
)

# Decode watermark from audio file
decode = client.audio.decode("suspect.mp3")
if decode.watermarked:
    print(f"Token: {decode.token_id}")

Notebook (Notes) Management

# Create a public notebook for a token
notebook = client.notebooks.create(
    token_id=token.id,
    note_name="Release Notes",
    text_content="## Version 1.0\n\nInitial release.",
    is_public=True
)

# Create a private notebook (default password: "123")
private_nb = client.notebooks.create(
    token_id=token.id,
    note_name="Private Notes",
    text_content="Confidential content",
    is_public=False,
    credential_val="123"  # Optional, defaults to "123"
)

# Upload media to notebook
client.notebooks.upload_media(
    note_id=notebook.id,
    file="cover.jpg"
)

# List notebooks for a token
notebooks = client.notebooks.list(token_id=token.id)

Quota Checking

# Get all quotas
quotas = client.quotas.get_all()
for quota in quotas:
    print(f"{quota.service_name}: {quota.remaining}/{quota.quota_limit}")

# Check if encoding is available
if client.quotas.check_encode_available(duration_seconds=300):
    # Proceed with encoding
    pass

Error Handling

from ofspectrum import (
    OfSpectrumError,
    AuthenticationError,
    RateLimitError,
    QuotaExceededError,
    WatermarkExistsError,
    ResourceNotFoundError,
)

try:
    result = client.audio.encode(audio="input.mp3", token_id="...")
except RateLimitError as e:
    print(f"Rate limited! Retry after {e.retry_after} seconds")
except QuotaExceededError as e:
    print(f"Quota exceeded for {e.service}")
except WatermarkExistsError:
    print("Audio already has a watermark!")
except AuthenticationError:
    print("Invalid API key")
except OfSpectrumError as e:
    print(f"API error: {e.code} - {e.message}")

Retry Logic

from ofspectrum import OfSpectrum, RetryConfig, with_retry

# Use built-in retry decorator
@with_retry(RetryConfig(max_retries=3))
def encode_with_retry():
    return client.audio.encode(...)

# Or configure retry globally
config = RetryConfig(
    max_retries=5,
    initial_delay=1.0,
    max_delay=60.0,
    exponential_base=2.0,
    jitter=True
)

Context Manager

# Recommended: Use context manager for automatic cleanup
with OfSpectrum(api_key="your_api_key") as client:
    tokens = client.tokens.list()

Configuration

client = OfSpectrum(
    api_key="your_api_key",
    base_url="https://api.ofspectrum.com/api/v1",  # Optional: custom base URL
    timeout=120.0  # Optional: request timeout in seconds
)

Requirements

  • Python 3.8+
  • httpx >= 0.24.0

License

MIT License

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

ofspectrum-1.1.1.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

ofspectrum-1.1.1-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file ofspectrum-1.1.1.tar.gz.

File metadata

  • Download URL: ofspectrum-1.1.1.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ofspectrum-1.1.1.tar.gz
Algorithm Hash digest
SHA256 b66a7042196849f08af47a0d01c7d4865c051663ef0c7a6de2a2d4445670232d
MD5 5aba9a255f603668f9c3620a3bb9117f
BLAKE2b-256 b7eb9e853e829aeb66188a756307eb80c91c44ee144150c56dff77f93156e470

See more details on using hashes here.

Provenance

The following attestation bundles were made for ofspectrum-1.1.1.tar.gz:

Publisher: publish.yml on ofspectrum/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ofspectrum-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: ofspectrum-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ofspectrum-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53624d3d7a94783db8d9aac03accf2f048c576da39bd58a6acaff1c54360a680
MD5 10b8e31eace2ea27322977285a8f9404
BLAKE2b-256 72ab01ae99f296ef3c5fd597102248d1ff179531066ce2358549b47a2a21cae1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ofspectrum-1.1.1-py3-none-any.whl:

Publisher: publish.yml on ofspectrum/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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