Skip to main content

High quality, one-dimensional sample-rate conversion library

Project description

Python-SoXR

GitHub PyPI Read the Docs

High quality, one-dimensional sample-rate conversion library for Python.

Python-SoXR is a Python wrapper of libsoxr.

Installation

pip install soxr

If installation fails, upgrade pip with python -m pip install --upgrade pip and try again.

Basic usage

import soxr

y = soxr.resample(
    x,          # 1D(mono) or 2D(frames, channels) array input
    48000,      # input samplerate
    16000       # target samplerate
)

If input is not numpy.ndarray, it will be converted to numpy.ndarray(dtype='float32').
dtype should be one of float32, float64, int16, int32.

Output is numpy.ndarray with same dimension and data type of input.

Streaming usage

Use ResampleStream for real-time processing or very long signal.

import soxr

rs = soxr.ResampleStream(
    44100,              # input samplerate
    16000,              # target samplerate
    1,                  # channel(s)
    dtype='float32'     # data type (default = 'float32')
)

eof = False
while not eof:
    # Get chunk
    ...

    y_chunk = rs.resample_chunk(
        x,              # 1D(mono) or 2D(frames, channels) array input
        last=eof        # Set True at end of input
    )

Output frame count may not be consistent. This is normal operation.
(ex. [0, 0, 0, 186, 186, 166, 186, 186, 168, ...])

Requirement

x86 and ARM processors are supported.

Neon extension is required for ARM CPUs. Without Neon, it may crash or return inaccurate result.

Benchmark

Sweep, impulse, speed compairsion with other Python resamplers.

https://colab.research.google.com/drive/1XgSOvWlRIau1FYwQG_yRSAhDK3KB8bEL?usp=sharing

Speed comparison summary

Downsampling 10 sec of 48000 Hz to 44100 Hz.
Ran on Google Colab.

Library Time on CPU (ms)
soxr (HQ) 7.2
scipy.signal.resample 13.4
soxr (VHQ) 15.8
torchaudio 19.2
lilfilter 21.4
julius 23.1
resampy (kaiser_fast) 62.6
samplerate (sinc_medium) 92.5
resampy (kaiser_best) 256
samplerate (sinc_best) 397

Technical detail

For technical details behind resampler, see libsoxr docs.

Credit and License

Python-SoXR is LGPL v2.1+ licensed, following libsoxr's license.

OSS libraries used

libsoxr (LGPLv2.1+)

The SoX Resampler library
https://sourceforge.net/projects/soxr/

Python-SoXR is a Python wrapper of libsoxr.

PFFFT (BSD-like)

PFFFT: a pretty fast FFT.
https://bitbucket.org/jpommier/pffft/

libsoxr dependency.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

soxr-0.2.6-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (379.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

soxr-0.2.6-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (388.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

soxr-0.2.6-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (385.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

soxr-0.2.6-cp310-cp310-win_amd64.whl (378.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

soxr-0.2.6-cp310-cp310-win32.whl (342.2 kB view hashes)

Uploaded CPython 3.10 Windows x86

soxr-0.2.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

soxr-0.2.6-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

soxr-0.2.6-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

soxr-0.2.6-cp39-cp39-win_amd64.whl (377.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

soxr-0.2.6-cp39-cp39-win32.whl (341.6 kB view hashes)

Uploaded CPython 3.9 Windows x86

soxr-0.2.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

soxr-0.2.6-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

soxr-0.2.6-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

soxr-0.2.6-cp39-cp39-macosx_10_9_x86_64.whl (404.2 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

soxr-0.2.6-cp38-cp38-win_amd64.whl (378.4 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

soxr-0.2.6-cp38-cp38-win32.whl (342.4 kB view hashes)

Uploaded CPython 3.8 Windows x86

soxr-0.2.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

soxr-0.2.6-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

soxr-0.2.6-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

soxr-0.2.6-cp38-cp38-macosx_10_9_x86_64.whl (406.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

soxr-0.2.6-cp37-cp37m-win_amd64.whl (376.3 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

soxr-0.2.6-cp37-cp37m-win32.whl (340.7 kB view hashes)

Uploaded CPython 3.7m Windows x86

soxr-0.2.6-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

soxr-0.2.6-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

soxr-0.2.6-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

soxr-0.2.6-cp37-cp37m-macosx_10_9_x86_64.whl (403.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

soxr-0.2.6-cp36-cp36m-win_amd64.whl (374.6 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

soxr-0.2.6-cp36-cp36m-win32.whl (339.4 kB view hashes)

Uploaded CPython 3.6m Windows x86

soxr-0.2.6-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

soxr-0.2.6-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

soxr-0.2.6-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

soxr-0.2.6-cp36-cp36m-macosx_10_9_x86_64.whl (401.8 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page