Skip to main content

Efficient audio seeking library with O(1) complexity. Automatically selects best seekable compression format for maximum compatibility.

Project description

Audio Seek

PyPI version Python Version License

A lightweight Python library designed for precision seeking and zero-waste decoding of compressed audio files with maximum cross-platform compatibility.

Key Features

  • O(1) Seeking: Sample-accurate seeking without parsing frame headers or processing bit reservoirs.
  • Zero Waste: Reads and decodes only the requested time slice. No "warm-up" samples or overlapping frames required.
  • Smart Format Selection: Automatically selects the best available seekable compression format based on your system.
  • Cross-Platform Compatibility: Tests seekability at runtime and falls back gracefully to ensure reliability.
  • High Efficiency: Wraps libsndfile (via pysoundfile) for C-level performance.

Installation

pip install audio-seek

Quick Start

Convert Audio to Seekable Format

from audio_seek import AudioSeek

# Convert MP3 to seekable WAV format
AudioSeek.convert_from_file(
    input_path="input.mp3",
    output_path="output.wav",
    target_sr=16000,
    bits=4,  # Auto-selects best seekable format
)

Read Specific Audio Segments (O(1) Seeking)

from audio_seek import read_audio_segment

# Read 5 seconds starting at 2 minutes
segment = read_audio_segment(
    file_path="long_audio.wav",
    start_sec=120.0,
    duration_sec=5.0,
)
# Returns numpy array of shape (sample_rate * duration,)

Get Duration Without Loading Audio

from audio_seek import AudioSeek

# O(1) operation - only reads header
duration = AudioSeek.get_duration("audio.wav")
print(f"Duration: {duration:.2f}s")

Write Numpy Array to Seekable Format

import numpy as np
from audio_seek import AudioSeek

# Create audio data
audio_data = np.sin(2 * np.pi * 440 * np.linspace(0, 1, 16000)).astype(np.float32)

# Write to seekable WAV
AudioSeek.write(
    file_path="output.wav",
    data=audio_data,
    sample_rate=16000,
    bits_per_sample=4,
)

How It Works

Unlike formats like MP3 or AAC that require sequential decoding, audio-seek uses compression formats that support true random access:

  1. Runtime Format Detection: Tests available formats for seekability on your system
  2. Smart Fallback: Automatically selects IMA_ADPCM or MS_ADPCM if ideal formats aren't available
  3. Guaranteed Seekability: Only uses formats that pass actual seek tests

Use Cases

Ideal for applications requiring low-latency access to specific segments of long audio recordings:

  • Machine Learning: Dataset slicing without loading entire files
  • Web Services: Real-time audio segment delivery
  • Telephony: Archive retrieval and call analysis
  • Audio Processing: Random access pipelines

Requirements

  • Python >= 3.11
  • numpy
  • soundfile
  • librosa (for format conversion)

Testing

pytest tests/ -v

License

MIT License - see 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

audio_seek-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

audio_seek-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file audio_seek-0.1.0.tar.gz.

File metadata

  • Download URL: audio_seek-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.14 Darwin/25.1.0

File hashes

Hashes for audio_seek-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb6ee8c1f086d233577ac897cf847e836a43d227894da07b538520170c72cd5c
MD5 6b325d582dcb27be5d7016aa513fbb92
BLAKE2b-256 b3429ce149e93e95f199dc532df1a74416af9e2b82e7142636193f65d09e54c8

See more details on using hashes here.

File details

Details for the file audio_seek-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: audio_seek-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.14 Darwin/25.1.0

File hashes

Hashes for audio_seek-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf5eed294b76746faf73359ed8092429e6dbf32248b9cd0fe23b672de4b6755f
MD5 43c66823cf9cf574a76a917156096c23
BLAKE2b-256 cac37547ac67f325bce539fb2339f5793a5d86650db8853cfb87457eeb2a0ae4

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