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.2.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.2-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ofspectrum-1.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 bf4afe5cf98f21c0e0988800293a40bca9de447396d6c2208a09e9fcdb770297
MD5 7b8bc25f8477a6a8205f2b42a19b2309
BLAKE2b-256 e45d1af4b9061430c84f4b7254ae3c40438e6d8fc9161885a2222732c5288c75

See more details on using hashes here.

Provenance

The following attestation bundles were made for ofspectrum-1.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: ofspectrum-1.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5c038e4f76c540030e1e10b65d60491d9907ef3814d3b6c11209ba1f37ee7572
MD5 30f455e1032a52b758b47e22505ef469
BLAKE2b-256 4b5bb32496ee2a507615b463fb8fa848c68e6c5bc98a24ff75f9ea7382a4e22d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ofspectrum-1.1.2-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